Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FileSystem and conforming types as Sendable #402

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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