Skip to content

Commit 000c1da

Browse files
authored
TSCBasic: make FS-related value types Sendable (#382)
When using `FileSystem`-related code in `async` context we need these types to be `Sendable`.
1 parent 539935f commit 000c1da

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Sources/TSCBasic/ByteString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Foundation
2323
/// strings or and by eliminating wasted space in growable arrays). For
2424
/// construction of byte arrays, clients should use the `WritableByteStream` class
2525
/// and then convert to a `ByteString` when complete.
26-
public struct ByteString: ExpressibleByArrayLiteral, Hashable {
26+
public struct ByteString: ExpressibleByArrayLiteral, Hashable, Sendable {
2727
/// The buffer contents.
2828
@usableFromInline
2929
internal var _bytes: [UInt8]

Sources/TSCBasic/FileInfo.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

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

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

1111
import Foundation
1212

13+
#if swift(<5.6)
14+
extension FileAttributeType: UnsafeSendable {}
15+
extension Date: UnsafeSendable {}
16+
#endif
17+
1318
/// File system information for a particular file.
14-
public struct FileInfo: Equatable, Codable {
19+
public struct FileInfo: Equatable, Codable, Sendable {
1520

1621
/// The device number.
1722
public let device: UInt64

Sources/TSCBasic/FileSystem.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ public extension FileSystemError {
111111
}
112112

113113
/// Defines the file modes.
114-
public enum FileMode {
114+
public enum FileMode: Sendable {
115115

116-
public enum Option: Int {
116+
public enum Option: Int, Sendable {
117117
case recursive
118118
case onlyFiles
119119
}
@@ -122,17 +122,17 @@ public enum FileMode {
122122
case userWritable
123123
case executable
124124

125-
internal var setMode: (Int16) -> Int16 {
125+
public func setMode(_ originalMode: Int16) -> Int16 {
126126
switch self {
127127
case .userUnWritable:
128128
// r-x rwx rwx
129-
return {$0 & 0o577}
129+
return originalMode & 0o577
130130
case .userWritable:
131131
// -w- --- ---
132-
return {$0 | 0o200}
132+
return originalMode | 0o200
133133
case .executable:
134134
// --x --x --x
135-
return {$0 | 0o111}
135+
return originalMode | 0o111
136136
}
137137
}
138138
}

0 commit comments

Comments
 (0)