@@ -153,6 +153,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
153
153
open func copy( with zone: NSZone ? = nil ) -> Any {
154
154
if isFileURL {
155
155
let newURL = CFURLCreateWithString ( kCFAllocatorSystemDefault, relativeString. _cfObject, self . baseURL? . _cfObject) !
156
+
156
157
if let storage = _resourceStorageIfPresent {
157
158
let newStorage = URLResourceValuesStorage ( copying: storage)
158
159
_CFURLSetResourceInfo ( newURL, newStorage)
@@ -206,6 +207,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
206
207
if validPathSeps. contains ( where: { thePath. hasSuffix ( String ( $0) ) } ) {
207
208
isDir = true
208
209
} else {
210
+ #if !os(WASI)
209
211
let absolutePath : String
210
212
if let absPath = baseURL? . appendingPathComponent ( path) . path {
211
213
absolutePath = absPath
@@ -214,6 +216,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
214
216
}
215
217
216
218
let _ = FileManager . default. fileExists ( atPath: absolutePath, isDirectory: & isDir)
219
+ #endif
217
220
}
218
221
219
222
self . init ( fileURLWithPath: thePath, isDirectory: isDir. boolValue, relativeTo: baseURL)
@@ -230,9 +233,11 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
230
233
if validPathSeps. contains ( where: { thePath. hasSuffix ( String ( $0) ) } ) {
231
234
isDir = true
232
235
} else {
236
+ #if !os(WASI)
233
237
if !FileManager. default. fileExists ( atPath: path, isDirectory: & isDir) {
234
238
isDir = false
235
239
}
240
+ #endif
236
241
}
237
242
super. init ( )
238
243
_CFURLInitWithFileSystemPathRelativeToBase ( _cfObject, thePath. _cfObject, kCFURLPlatformPathStyle, isDir. boolValue, nil )
@@ -542,6 +547,9 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
542
547
// TODO: should be `checkResourceIsReachableAndReturnError` with autoreleased error parameter.
543
548
// Currently Autoreleased pointers is not supported on Linux.
544
549
open func checkResourceIsReachable( ) throws -> Bool {
550
+ #if os(WASI)
551
+ return false
552
+ #else
545
553
guard isFileURL,
546
554
let path = path else {
547
555
throw NSError ( domain: NSCocoaErrorDomain,
@@ -557,6 +565,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
557
565
}
558
566
559
567
return true
568
+ #endif
560
569
}
561
570
562
571
/* Returns a file path URL that refers to the same resource as a specified URL. File path URLs use a file system style path. An error will occur if the url parameter is not a file URL. A file reference URL's resource must exist and be reachable to be converted to a file path URL. Symbol is present in iOS 4, but performs no operation.
@@ -841,6 +850,9 @@ extension NSURL {
841
850
842
851
open func appendingPathComponent( _ pathComponent: String ) -> URL ? {
843
852
var result : URL ? = appendingPathComponent ( pathComponent, isDirectory: false )
853
+
854
+ // File URLs can't be handled on WASI without file system access
855
+ #if !os(WASI)
844
856
// Since we are appending to a URL, path seperators should
845
857
// always be '/', even if we're on Windows
846
858
if !pathComponent. hasSuffix ( " / " ) && isFileURL {
@@ -852,6 +864,7 @@ extension NSURL {
852
864
}
853
865
854
866
}
867
+ #endif
855
868
return result
856
869
}
857
870
@@ -878,7 +891,7 @@ extension NSURL {
878
891
// In remaining cases it works just like URLByResolvingSymlinksInPath.
879
892
return _resolveSymlinksInPath ( excludeSystemDirs: true , preserveDirectoryFlag: true )
880
893
}
881
-
894
+
882
895
open var resolvingSymlinksInPath : URL ? {
883
896
return _resolveSymlinksInPath ( excludeSystemDirs: true )
884
897
}
@@ -896,8 +909,12 @@ extension NSURL {
896
909
if selfPath. isAbsolutePath {
897
910
absolutePath = selfPath
898
911
} else {
912
+ #if os(WASI)
913
+ return nil
914
+ #else
899
915
let workingDir = FileManager . default. currentDirectoryPath
900
916
absolutePath = workingDir. _bridgeToObjectiveC ( ) . appendingPathComponent ( selfPath)
917
+ #endif
901
918
}
902
919
903
920
@@ -918,15 +935,20 @@ extension NSURL {
918
935
919
936
default :
920
937
resolvedPath = resolvedPath. _bridgeToObjectiveC ( ) . appendingPathComponent ( component)
938
+ #if !os(WASI)
921
939
if let destination = FileManager . default. _tryToResolveTrailingSymlinkInPath ( resolvedPath) {
922
940
resolvedPath = destination
923
941
}
942
+ #endif
924
943
}
925
944
}
926
945
927
946
// It might be a responsibility of NSURL(fileURLWithPath:). Check it.
928
947
var isExistingDirectory : ObjCBool = false
948
+
949
+ #if !os(WASI)
929
950
let _ = FileManager . default. fileExists ( atPath: resolvedPath, isDirectory: & isExistingDirectory)
951
+ #endif
930
952
931
953
if excludeSystemDirs {
932
954
resolvedPath = resolvedPath. _tryToRemovePathPrefix ( " /private " ) ?? resolvedPath
@@ -1005,6 +1027,7 @@ extension NSURL : _StructTypeBridgeable {
1005
1027
1006
1028
// -----
1007
1029
1030
+ #if !os(WASI)
1008
1031
internal func _CFSwiftURLCopyResourcePropertyForKey( _ url: CFTypeRef , _ key: CFString , _ valuePointer: UnsafeMutablePointer < Unmanaged < CFTypeRef > ? > ? , _ errorPointer: UnsafeMutablePointer < Unmanaged < CFError > ? > ? ) -> _DarwinCompatibleBoolean {
1009
1032
do {
1010
1033
let key = URLResourceKey ( rawValue: key. _swiftObject)
@@ -1538,6 +1561,7 @@ fileprivate extension URLResourceValuesStorage {
1538
1561
}
1539
1562
}
1540
1563
}
1564
+ #endif
1541
1565
1542
1566
// -----
1543
1567
0 commit comments