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

Mark types conforming to FileSystem as Sendable #6318

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/Basics/FileSystem/TemporaryFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import _Concurrency
import Foundation
@preconcurrency import TSCBasic
import TSCBasic

/// Creates a temporary directory and evaluates a closure with the directory path as an argument.
/// The temporary directory will live on disk while the closure is evaluated and will be deleted when
Expand Down
5 changes: 4 additions & 1 deletion Sources/Basics/FileSystem/VirtualFileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public class VirtualFileSystem: FileSystem {
return node.children.map { $0.name }
}

public var currentWorkingDirectory: AbsolutePath? = nil
public let currentWorkingDirectory: AbsolutePath? = nil

public func changeCurrentWorkingDirectory(to path: AbsolutePath) throws {
throw Errors.readOnlyFileSystem
Expand Down Expand Up @@ -246,3 +246,6 @@ public class VirtualFileSystem: FileSystem {
return FileInfo(attrs)
}
}

// `VirtualFileSystem` is read-only, so it can be marked as `Sendable`.
extension VirtualFileSystem: @unchecked Sendable {}
10 changes: 5 additions & 5 deletions Sources/PackageRegistry/SignatureValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct SignatureValidation {
fileSystem: FileSystem,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<SigningEntity?, Error>) -> Void
completion: @Sendable @escaping (Result<SigningEntity?, Error>) -> Void
) {
guard !self.skipSignatureValidation else {
return completion(.success(.none))
Expand Down Expand Up @@ -110,7 +110,7 @@ struct SignatureValidation {
fileSystem: FileSystem,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<SigningEntity?, Error>) -> Void
completion: @Sendable @escaping (Result<SigningEntity?, Error>) -> Void
) {
do {
let versionMetadata = try self.versionMetadataProvider(package, version)
Expand Down Expand Up @@ -212,7 +212,7 @@ struct SignatureValidation {
fileSystem: FileSystem,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<SigningEntity?, Error>) -> Void
completion: @Sendable @escaping (Result<SigningEntity?, Error>) -> Void
) {
guard !self.skipSignatureValidation else {
return completion(.success(.none))
Expand Down Expand Up @@ -245,7 +245,7 @@ struct SignatureValidation {
fileSystem: FileSystem,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<SigningEntity?, Error>) -> Void
completion: @Sendable @escaping (Result<SigningEntity?, Error>) -> Void
) {
do {
let versionMetadata = try self.versionMetadataProvider(package, version)
Expand Down Expand Up @@ -352,7 +352,7 @@ struct SignatureValidation {
configuration: RegistryConfiguration.Security.Signing,
fileSystem: FileSystem,
observabilityScope: ObservabilityScope,
completion: @escaping (Result<SigningEntity?, Error>) -> Void
completion: @Sendable @escaping (Result<SigningEntity?, Error>) -> Void
) {
Task {
do {
Expand Down
3 changes: 3 additions & 0 deletions Sources/SPMTestSupport/InMemoryGitRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ extension InMemoryGitRepository: WorkingCheckout {
}
}

// Public mutation of `InMemoryGitRepository` is protected with a lock.
extension InMemoryGitRepository: @unchecked Sendable {}

/// This class implement provider for in memory git repository.
public final class InMemoryGitRepositoryProvider: RepositoryProvider {
/// Contains the repository added to this provider.
Expand Down
3 changes: 3 additions & 0 deletions Sources/SourceControl/GitRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,9 @@ private class GitFileSystemView: FileSystem {
}
}

// State of `GitFileSystemView` is protected with `ThreadSafeKeyValueStore`.
extension GitFileSystemView: @unchecked Sendable {}

// MARK: - Errors

private struct GitShellError: Error {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BasicsTests/URLSessionHTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ private class MockURLProtocol: URLProtocol {
}
}

class FailingFileSystem: FileSystem {
final class FailingFileSystem: FileSystem {
var currentWorkingDirectory: AbsolutePath? {
fatalError("unexpected call")
}
Expand Down