Skip to content

Commit ce56f1c

Browse files
committedJul 30, 2024
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 c0a485e commit ce56f1c

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
@@ -482,7 +482,7 @@ extension _FileManagerImpl {
482482
#endif
483483
}
484484

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

627627
var attributes = statAtPath.fileAttributes
628628
try? Self._catInfo(for: URL(filePath: path, directoryHint: .isDirectory), statInfo: statAtPath, into: &attributes)
629-
629+
#if !os(WASI) // WASI does not support extended attributes
630630
if let extendedAttrs = try? _extendedAttributes(at: fsRep, followSymlinks: false) {
631631
attributes[._extendedAttributes] = extendedAttrs
632632
}
633+
#endif
633634

634635
#if !targetEnvironment(simulator) && FOUNDATION_FRAMEWORK
635636
if statAtPath.isRegular || statAtPath.isDirectory {
@@ -691,6 +692,9 @@ extension _FileManagerImpl {
691692
]
692693
}
693694
}
695+
#elseif os(WASI)
696+
// WASI does not support file system attributes
697+
return [:]
694698
#else
695699
try fileManager.withFileSystemRepresentation(for: path) { rep in
696700
guard let rep else {
@@ -918,7 +922,12 @@ extension _FileManagerImpl {
918922
try Self._setCatInfoAttributes(attributes, path: path)
919923

920924
if let extendedAttrs = attributes[.init("NSFileExtendedAttributes")] as? [String : Data] {
925+
#if os(WASI)
926+
// WASI does not support extended attributes
927+
throw CocoaError.errorWithFilePath(.featureUnsupported, path)
928+
#else
921929
try Self._setAttributes(extendedAttrs, at: fileSystemRepresentation, followSymLinks: false)
930+
#endif
922931
}
923932

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

‎Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ extension _FileManagerImpl {
169169
#endif
170170
}
171171

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

0 commit comments

Comments
 (0)