Skip to content

Commit b239506

Browse files
Guard out extended or fs attributes related code on WASI
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 5463e8e commit b239506

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,13 @@ extension _FileManagerImpl {
484484
#endif
485485
}
486486

487-
#if !os(Windows)
487+
#if os(Windows)
488+
#elseif os(WASI)
489+
private func _extendedAttributes(at path: UnsafePointer<CChar>, followSymlinks: Bool) throws -> [String : Data]? {
490+
// WASI does not support extended attributes
491+
return nil
492+
}
493+
#else
488494
private func _extendedAttribute(_ key: UnsafePointer<CChar>, at path: UnsafePointer<CChar>, followSymlinks: Bool) throws -> Data? {
489495
#if canImport(Darwin)
490496
var size = getxattr(path, key, nil, 0, 0, followSymlinks ? 0 : XATTR_NOFOLLOW)
@@ -693,6 +699,9 @@ extension _FileManagerImpl {
693699
]
694700
}
695701
}
702+
#elseif os(WASI)
703+
// WASI does not support file system attributes
704+
return [:]
696705
#else
697706
try fileManager.withFileSystemRepresentation(for: path) { rep in
698707
guard let rep else {

Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ extension _FileManagerImpl {
173173
#endif
174174
}
175175

176-
#if !os(Windows)
176+
#if os(Windows)
177+
#elseif os(WASI)
178+
static func _setAttributes(_ attributes: [String : Data], at path: UnsafePointer<CChar>, followSymLinks: Bool) throws {
179+
// WASI doesn't have extended attributes, so just ignore the request.
180+
}
181+
#else
177182
static func _setAttribute(_ key: UnsafePointer<CChar>, value: Data, at path: UnsafePointer<CChar>, followSymLinks: Bool) throws {
178183
try value.withUnsafeBytes { buffer in
179184
#if canImport(Darwin)

0 commit comments

Comments
 (0)