Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard out extended or fs attributes related code on WASI #784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Sources/FoundationEssentials/FileManager/FileManager+Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ extension _FileManagerImpl {
#endif
}

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

var attributes = statAtPath.fileAttributes
try? Self._catInfo(for: URL(filePath: path, directoryHint: .isDirectory), statInfo: statAtPath, into: &attributes)

#if !os(WASI) // WASI does not support extended attributes
if let extendedAttrs = try? _extendedAttributes(at: fsRep, followSymlinks: false) {
attributes[._extendedAttributes] = extendedAttrs
}
#endif

#if !targetEnvironment(simulator) && FOUNDATION_FRAMEWORK
if statAtPath.isRegular || statAtPath.isDirectory {
Expand Down Expand Up @@ -691,6 +692,9 @@ extension _FileManagerImpl {
]
}
}
#elseif os(WASI)
// WASI does not support file system attributes
return [:]
#else
try fileManager.withFileSystemRepresentation(for: path) { rep in
guard let rep else {
Expand Down Expand Up @@ -918,7 +922,12 @@ extension _FileManagerImpl {
try Self._setCatInfoAttributes(attributes, path: path)

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

if let date = attributes[.modificationDate] as? Date {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ extension _FileManagerImpl {
#endif
}

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