Skip to content

TSCBasic: make FS-related value types Sendable #382

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

Merged
merged 5 commits into from
Jan 19, 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/TSCBasic/ByteString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Foundation
/// strings or and by eliminating wasted space in growable arrays). For
/// construction of byte arrays, clients should use the `WritableByteStream` class
/// and then convert to a `ByteString` when complete.
public struct ByteString: ExpressibleByArrayLiteral, Hashable {
public struct ByteString: ExpressibleByArrayLiteral, Hashable, Sendable {
/// The buffer contents.
@usableFromInline
internal var _bytes: [UInt8]
Expand Down
9 changes: 7 additions & 2 deletions Sources/TSCBasic/FileInfo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand All @@ -10,8 +10,13 @@

import Foundation

#if swift(<5.6)
extension FileAttributeType: UnsafeSendable {}
extension Date: UnsafeSendable {}
#endif

/// File system information for a particular file.
public struct FileInfo: Equatable, Codable {
public struct FileInfo: Equatable, Codable, Sendable {

/// The device number.
public let device: UInt64
Expand Down
12 changes: 6 additions & 6 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public extension FileSystemError {
}

/// Defines the file modes.
public enum FileMode {
public enum FileMode: Sendable {

public enum Option: Int {
public enum Option: Int, Sendable {
case recursive
case onlyFiles
}
Expand All @@ -122,17 +122,17 @@ public enum FileMode {
case userWritable
case executable

internal var setMode: (Int16) -> Int16 {
public func setMode(_ originalMode: Int16) -> Int16 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to pull in some of the FS-related code into SwiftPM, but that depends on this function being public. That was also a good opportunity to convert it from this unconventional var-returning-a-closure notation.

switch self {
case .userUnWritable:
// r-x rwx rwx
return {$0 & 0o577}
return originalMode & 0o577
case .userWritable:
// -w- --- ---
return {$0 | 0o200}
return originalMode | 0o200
case .executable:
// --x --x --x
return {$0 | 0o111}
return originalMode | 0o111
}
}
}
Expand Down