From 189d1f9f79ce99ddd880a9ecb8d63d24277c01c2 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 19 Apr 2023 11:40:13 +0100 Subject: [PATCH] TSCBasic: make `LocalFileSystem` a struct `LocalFileSystem` doesn't contain any storage for state, it should be safely convertible to `struct`. For this we have to remove `AnyObject` requirement from the `FileSystem` protocol. As a nice benefit, `@unchecked Sendable` conformance on `LocalFileSystem` can be removed as it now inherits `Sendable` conformance from `FileSystem`. --- Sources/TSCBasic/FileSystem.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Sources/TSCBasic/FileSystem.swift b/Sources/TSCBasic/FileSystem.swift index 22d4164a..ef4208ea 100644 --- a/Sources/TSCBasic/FileSystem.swift +++ b/Sources/TSCBasic/FileSystem.swift @@ -146,7 +146,7 @@ public enum FileMode: Sendable { /// substitute a virtual file system or redirect file system operations. /// /// - Note: All of these APIs are synchronous and can block. -public protocol FileSystem: AnyObject, Sendable { +public protocol FileSystem: Sendable { /// Check whether the given path exists and is accessible. func exists(_ path: AbsolutePath, followSymlink: Bool) -> Bool @@ -296,7 +296,7 @@ public extension FileSystem { } /// Concrete FileSystem implementation which communicates with the local file system. -private final class LocalFileSystem: FileSystem { +private struct LocalFileSystem: FileSystem { func isExecutableFile(_ path: AbsolutePath) -> Bool { // Our semantics doesn't consider directories. return (self.isFile(path) || self.isSymlink(path)) && FileManager.default.isExecutableFile(atPath: path.pathString) @@ -1176,9 +1176,6 @@ public var localFileSystem: FileSystem { } } -// `LocalFileSystem` doesn't hold any internal state and all of its underlying operations are blocking. -extension LocalFileSystem: @unchecked Sendable {} - extension FileSystem { /// Print the filesystem tree of the given path. ///