Skip to content

Commit

Permalink
Make FileSystem and confirming types as Sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov committed Mar 18, 2023
1 parent cab96f6 commit 4d14e6c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 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 {
public protocol FileSystem: AnyObject, Sendable {
/// Check whether the given path exists and is accessible.
func exists(_ path: AbsolutePath, followSymlink: Bool) -> Bool

Expand Down Expand Up @@ -548,8 +548,6 @@ private class LocalFileSystem: FileSystem {
}
}

// FIXME: This class does not yet support concurrent mutation safely.
//
/// Concrete FileSystem implementation which simulates an empty disk.
public class InMemoryFileSystem: FileSystem {

Expand Down Expand Up @@ -1008,6 +1006,9 @@ public class InMemoryFileSystem: FileSystem {
}
}

// Internal state of `InMemoryFileSystem` is protected with a lock in all of its `public` methods.
extension InMemoryFileSystem: @unchecked Sendable {}

/// A rerooted view on an existing FileSystem.
///
/// This is a simple wrapper which creates a new FileSystem view into a subtree
Expand Down Expand Up @@ -1159,9 +1160,16 @@ public class RerootedFileSystemView: FileSystem {
}
}

// `RerootedFileSystemView` doesn't hold any internal state and can be considered `Sendable` since
// `underlyingFileSystem` is required to be `Sendable`.
extension RerootedFileSystemView: @unchecked Sendable {}

/// Public access to the local FS proxy.
public var localFileSystem: FileSystem = LocalFileSystem()

// `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 4d14e6c

Please sign in to comment.