@@ -137,6 +137,33 @@ public enum FileMode: Sendable {
137
137
}
138
138
}
139
139
140
+ /// Extended file system attributes that can applied to a given file path. See also ``FileSystem/hasAttribute(_:_:)``.
141
+ public enum FileSystemAttribute : RawRepresentable {
142
+ #if canImport(Darwin)
143
+ case quarantine
144
+ #endif
145
+
146
+ public init ? ( rawValue: String ) {
147
+ switch rawValue {
148
+ #if canImport(Darwin)
149
+ case " com.apple.quarantine " :
150
+ self = . quarantine
151
+ #endif
152
+ default :
153
+ return nil
154
+ }
155
+ }
156
+
157
+ public var rawValue : String {
158
+ switch self {
159
+ #if canImport(Darwin)
160
+ case . quarantine:
161
+ return " com.apple.quarantine "
162
+ #endif
163
+ }
164
+ }
165
+ }
166
+
140
167
// FIXME: Design an asynchronous story?
141
168
//
142
169
/// Abstracted access to file system operations.
@@ -169,10 +196,13 @@ public protocol FileSystem: Sendable {
169
196
/// Check whether the given path is accessible and writable.
170
197
func isWritable( _ path: AbsolutePath ) -> Bool
171
198
172
- /// Returns `true` if a given path has a quarantine attribute applied if when file system supports this attribute.
173
- /// Returns `false` if such attribute is not applied or it isn't supported.
199
+ @available ( * , deprecated, message: " use `hasAttribute(_:_:)` instead " )
174
200
func hasQuarantineAttribute( _ path: AbsolutePath ) -> Bool
175
201
202
+ /// Returns `true` if a given path has an attribute with a given name applied when file system supports this
203
+ /// attribute. Returns `false` if such attribute is not applied or it isn't supported.
204
+ func hasAttribute( _ name: FileSystemAttribute , _ path: AbsolutePath ) -> Bool
205
+
176
206
// FIXME: Actual file system interfaces will allow more efficient access to
177
207
// more data than just the name here.
178
208
//
@@ -307,6 +337,8 @@ public extension FileSystem {
307
337
}
308
338
309
339
func hasQuarantineAttribute( _ path: AbsolutePath ) -> Bool { false }
340
+
341
+ func hasAttribute( _ name: FileSystemAttribute , _ path: AbsolutePath ) -> Bool { false }
310
342
}
311
343
312
344
/// Concrete FileSystem implementation which communicates with the local file system.
@@ -355,9 +387,9 @@ private struct LocalFileSystem: FileSystem {
355
387
return FileInfo ( attrs)
356
388
}
357
389
358
- func hasQuarantineAttribute ( _ path: AbsolutePath ) -> Bool {
390
+ func hasAttribute ( _ name : FileSystemAttribute , _ path: AbsolutePath ) -> Bool {
359
391
#if canImport(Darwin)
360
- let bufLength = getxattr ( path. pathString, " com.apple.quarantine " , nil , 0 , 0 , 0 )
392
+ let bufLength = getxattr ( path. pathString, name . rawValue , nil , 0 , 0 , 0 )
361
393
362
394
return bufLength > 0
363
395
#else
0 commit comments