Skip to content

Clean up some NO_FILESYSTEM paths #1210

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

Merged
merged 1 commit into from
Mar 13, 2025
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
8 changes: 6 additions & 2 deletions Sources/FoundationEssentials/Data/Data+Reading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import WinSDK
@preconcurrency import WASILibc
#endif

#if FOUNDATION_FRAMEWORK && NO_FILESYSTEM
@_spi(ENABLE_EXCLAVE_STORAGE) import C
#endif

func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
#if canImport(Darwin)
return fgetxattr(fd, name, value, size, position, options)
Expand Down Expand Up @@ -329,13 +333,13 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma
}

let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max)
let fileType = mode_t(filestat.st_mode) & S_IFMT
let fileType = mode_t(filestat.st_mode) & mode_t(S_IFMT)
#if !NO_FILESYSTEM
let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options)
#else
let shouldMap = false
#endif

if fileType != S_IFREG {
// EACCES is still an odd choice, but at least we have a better error for directories.
let code = (fileType == S_IFDIR) ? EISDIR : EACCES
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Data/Data+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

#if FOUNDATION_FRAMEWORK
internal import _ForSwiftFoundation
#if !NO_FILESYSTEM
internal import DarwinPrivate // for VREG
#endif
#endif

internal import _FoundationCShims

Expand Down
10 changes: 0 additions & 10 deletions Sources/FoundationEssentials/Data/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2135,10 +2135,6 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
/// - parameter options: Options for the read operation. Default value is `[]`.
/// - throws: An error in the Cocoa domain, if `url` cannot be read.
public init(contentsOf url: __shared URL, options: ReadingOptions = []) throws {
#if NO_FILESYSTEM
let d = try NSData(contentsOf: url, options: NSData.ReadingOptions(rawValue: options.rawValue))
self.init(referencing: d)
#else
if url.isFileURL {
self = try readDataFromFile(path: .url(url), reportProgress: true, options: options)
} else {
Expand All @@ -2150,16 +2146,10 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
try self.init(_contentsOfRemote: url, options: options)
#endif
}
#endif
}

internal init(contentsOfFile path: String, options: ReadingOptions = []) throws {
#if NO_FILESYSTEM
let d = try NSData(contentsOfFile: path, options: NSData.ReadingOptions(rawValue: options.rawValue))
self.init(referencing: d)
#else
self = try readDataFromFile(path: .path(path), reportProgress: true, options: options)
#endif
}

// -----------------------------------
Expand Down