Skip to content

Commit fab7195

Browse files
Guard out extended or fs attributes related code on WASI (#784)
This commit guards out the extended attributes and file system attributes related code on WASI as WASI does not support these features. Just return nothing or ignore the set request.
1 parent a8f1225 commit fab7195

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ extension _FileManagerImpl {
484484
#endif
485485
}
486486

487-
#if !os(Windows)
487+
#if !os(Windows) && !os(WASI)
488488
private func _extendedAttribute(_ key: UnsafePointer<CChar>, at path: UnsafePointer<CChar>, followSymlinks: Bool) throws -> Data? {
489489
#if canImport(Darwin)
490490
var size = getxattr(path, key, nil, 0, 0, followSymlinks ? 0 : XATTR_NOFOLLOW)
@@ -638,10 +638,11 @@ extension _FileManagerImpl {
638638

639639
var attributes = statAtPath.fileAttributes
640640
try? Self._catInfo(for: URL(filePath: path, directoryHint: .isDirectory), statInfo: statAtPath, into: &attributes)
641-
641+
#if !os(WASI) // WASI does not support extended attributes
642642
if let extendedAttrs = try? _extendedAttributes(at: fsRep, followSymlinks: false) {
643643
attributes[._extendedAttributes] = extendedAttrs
644644
}
645+
#endif
645646

646647
#if !targetEnvironment(simulator) && FOUNDATION_FRAMEWORK
647648
if statAtPath.isRegular || statAtPath.isDirectory {
@@ -703,6 +704,9 @@ extension _FileManagerImpl {
703704
]
704705
}
705706
}
707+
#elseif os(WASI)
708+
// WASI does not support file system attributes
709+
return [:]
706710
#else
707711
try fileManager.withFileSystemRepresentation(for: path) { rep in
708712
guard let rep else {
@@ -930,7 +934,12 @@ extension _FileManagerImpl {
930934
try Self._setCatInfoAttributes(attributes, path: path)
931935

932936
if let extendedAttrs = attributes[.init("NSFileExtendedAttributes")] as? [String : Data] {
937+
#if os(WASI)
938+
// WASI does not support extended attributes
939+
throw CocoaError.errorWithFilePath(.featureUnsupported, path)
940+
#else
933941
try Self._setAttributes(extendedAttrs, at: fileSystemRepresentation, followSymLinks: false)
942+
#endif
934943
}
935944

936945
if let date = attributes[.modificationDate] as? Date {

Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extension _FileManagerImpl {
173173
#endif
174174
}
175175

176-
#if !os(Windows)
176+
#if !os(Windows) && !os(WASI)
177177
static func _setAttribute(_ key: UnsafePointer<CChar>, value: Data, at path: UnsafePointer<CChar>, followSymLinks: Bool) throws {
178178
try value.withUnsafeBytes { buffer in
179179
#if canImport(Darwin)

0 commit comments

Comments
 (0)