Skip to content

Commit f0adc5e

Browse files
authored
(132269652) Avoid checking filesystem when constructing path errors (#762)
1 parent 42913b5 commit f0adc5e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/FoundationEssentials/URL/URL.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,15 +907,16 @@ public struct URL: Equatable, Sendable, Hashable {
907907
internal init?(_fileManagerFailableFileURLWithPath path: __shared String) {
908908
#if FOUNDATION_FRAMEWORK
909909
guard foundation_swift_url_enabled() else {
910-
let url = URL._converted(from: NSURL(fileURLWithPath: path.isEmpty ? "." : path))
910+
let url = URL._converted(from: NSURL(fileURLWithPath: path.isEmpty ? "." : path, isDirectory: path.utf8.last == ._slash))
911911
guard unsafeBitCast(url, to: UnsafeRawPointer?.self) != nil else {
912912
return nil
913913
}
914914
self.init(convertedReference: url)
915915
return
916916
}
917917
#endif
918-
self.init(filePath: path, directoryHint: .checkFileSystem)
918+
// Infer from the path to prevent a file system check for what is likely a non-existant, malformed, or inaccessible path
919+
self.init(filePath: path, directoryHint: .inferFromPath)
919920
}
920921

921922
/// Initializes a newly created URL using the contents of the given data, relative to a base URL.

0 commit comments

Comments
 (0)