Skip to content

Commit

Permalink
TSCBasic: make LocalFileSystem a struct (#410)
Browse files Browse the repository at this point in the history
`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`.
  • Loading branch information
MaxDesiatov authored Apr 20, 2023
1 parent 229b8e5 commit ae57c40
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
///
Expand Down

0 comments on commit ae57c40

Please sign in to comment.