Skip to content

Commit ae57c40

Browse files
authored
TSCBasic: make LocalFileSystem a struct (#410)
`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`.
1 parent 229b8e5 commit ae57c40

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Sources/TSCBasic/FileSystem.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public enum FileMode: Sendable {
146146
/// substitute a virtual file system or redirect file system operations.
147147
///
148148
/// - Note: All of these APIs are synchronous and can block.
149-
public protocol FileSystem: AnyObject, Sendable {
149+
public protocol FileSystem: Sendable {
150150
/// Check whether the given path exists and is accessible.
151151
func exists(_ path: AbsolutePath, followSymlink: Bool) -> Bool
152152

@@ -296,7 +296,7 @@ public extension FileSystem {
296296
}
297297

298298
/// Concrete FileSystem implementation which communicates with the local file system.
299-
private final class LocalFileSystem: FileSystem {
299+
private struct LocalFileSystem: FileSystem {
300300
func isExecutableFile(_ path: AbsolutePath) -> Bool {
301301
// Our semantics doesn't consider directories.
302302
return (self.isFile(path) || self.isSymlink(path)) && FileManager.default.isExecutableFile(atPath: path.pathString)
@@ -1176,9 +1176,6 @@ public var localFileSystem: FileSystem {
11761176
}
11771177
}
11781178

1179-
// `LocalFileSystem` doesn't hold any internal state and all of its underlying operations are blocking.
1180-
extension LocalFileSystem: @unchecked Sendable {}
1181-
11821179
extension FileSystem {
11831180
/// Print the filesystem tree of the given path.
11841181
///

0 commit comments

Comments
 (0)