Skip to content

Commit a95c2c8

Browse files
authored
Clean up some NO_FILESYSTEM paths (#1210)
1 parent 2ea76c3 commit a95c2c8

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

Sources/FoundationEssentials/Data/Data+Reading.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import WinSDK
3131
@preconcurrency import WASILibc
3232
#endif
3333

34+
#if FOUNDATION_FRAMEWORK && NO_FILESYSTEM
35+
@_spi(ENABLE_EXCLAVE_STORAGE) import C
36+
#endif
37+
3438
func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
3539
#if canImport(Darwin)
3640
return fgetxattr(fd, name, value, size, position, options)
@@ -329,13 +333,13 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma
329333
}
330334

331335
let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max)
332-
let fileType = mode_t(filestat.st_mode) & S_IFMT
336+
let fileType = mode_t(filestat.st_mode) & mode_t(S_IFMT)
333337
#if !NO_FILESYSTEM
334338
let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options)
335339
#else
336340
let shouldMap = false
337341
#endif
338-
342+
339343
if fileType != S_IFREG {
340344
// EACCES is still an odd choice, but at least we have a better error for directories.
341345
let code = (fileType == S_IFDIR) ? EISDIR : EACCES

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
#if FOUNDATION_FRAMEWORK
1414
internal import _ForSwiftFoundation
15+
#if !NO_FILESYSTEM
1516
internal import DarwinPrivate // for VREG
1617
#endif
18+
#endif
1719

1820
internal import _FoundationCShims
1921

Sources/FoundationEssentials/Data/Data.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,10 +2135,6 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
21352135
/// - parameter options: Options for the read operation. Default value is `[]`.
21362136
/// - throws: An error in the Cocoa domain, if `url` cannot be read.
21372137
public init(contentsOf url: __shared URL, options: ReadingOptions = []) throws {
2138-
#if NO_FILESYSTEM
2139-
let d = try NSData(contentsOf: url, options: NSData.ReadingOptions(rawValue: options.rawValue))
2140-
self.init(referencing: d)
2141-
#else
21422138
if url.isFileURL {
21432139
self = try readDataFromFile(path: .url(url), reportProgress: true, options: options)
21442140
} else {
@@ -2150,16 +2146,10 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
21502146
try self.init(_contentsOfRemote: url, options: options)
21512147
#endif
21522148
}
2153-
#endif
21542149
}
21552150

21562151
internal init(contentsOfFile path: String, options: ReadingOptions = []) throws {
2157-
#if NO_FILESYSTEM
2158-
let d = try NSData(contentsOfFile: path, options: NSData.ReadingOptions(rawValue: options.rawValue))
2159-
self.init(referencing: d)
2160-
#else
21612152
self = try readDataFromFile(path: .path(path), reportProgress: true, options: options)
2162-
#endif
21632153
}
21642154

21652155
// -----------------------------------

0 commit comments

Comments
 (0)