@@ -153,6 +153,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
153153 open func copy( with zone: NSZone ? = nil ) -> Any {
154154 if isFileURL {
155155 let newURL = CFURLCreateWithString ( kCFAllocatorSystemDefault, relativeString. _cfObject, self . baseURL? . _cfObject) !
156+
156157 if let storage = _resourceStorageIfPresent {
157158 let newStorage = URLResourceValuesStorage ( copying: storage)
158159 _CFURLSetResourceInfo ( newURL, newStorage)
@@ -186,7 +187,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
186187 aCoder. encode ( self . baseURL? . _nsObject, forKey: " NS.base " )
187188 aCoder. encode ( self . relativeString. _bridgeToObjectiveC ( ) , forKey: " NS.relative " )
188189 }
189-
190+
190191 public init ( fileURLWithPath path: String , isDirectory isDir: Bool , relativeTo baseURL: URL ? ) {
191192 super. init ( )
192193
@@ -198,14 +199,15 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
198199 _CFURLInitWithFileSystemPathRelativeToBase ( _cfObject, baseURL. path. _cfObject, kCFURLPlatformPathStyle, baseURL. hasDirectoryPath, nil )
199200 }
200201 }
201-
202+
202203 public convenience init ( fileURLWithPath path: String , relativeTo baseURL: URL ? ) {
203204 let thePath = _standardizedPath ( path)
204205
205206 var isDir : ObjCBool = false
206207 if validPathSeps. contains ( where: { thePath. hasSuffix ( String ( $0) ) } ) {
207208 isDir = true
208209 } else {
210+ #if !os(WASI)
209211 let absolutePath : String
210212 if let absPath = baseURL? . appendingPathComponent ( path) . path {
211213 absolutePath = absPath
@@ -214,6 +216,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
214216 }
215217
216218 let _ = FileManager . default. fileExists ( atPath: absolutePath, isDirectory: & isDir)
219+ #endif
217220 }
218221
219222 self . init ( fileURLWithPath: thePath, isDirectory: isDir. boolValue, relativeTo: baseURL)
@@ -230,9 +233,11 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
230233 if validPathSeps. contains ( where: { thePath. hasSuffix ( String ( $0) ) } ) {
231234 isDir = true
232235 } else {
236+ #if !os(WASI)
233237 if !FileManager. default. fileExists ( atPath: path, isDirectory: & isDir) {
234238 isDir = false
235239 }
240+ #endif
236241 }
237242 super. init ( )
238243 _CFURLInitWithFileSystemPathRelativeToBase ( _cfObject, thePath. _cfObject, kCFURLPlatformPathStyle, isDir. boolValue, nil )
@@ -243,7 +248,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
243248 let pathString = String ( cString: path)
244249 self . init ( fileURLWithPath: pathString, isDirectory: isDir, relativeTo: baseURL)
245250 }
246-
251+
247252 public convenience init ? ( string URLString: String ) {
248253 self . init ( string: URLString, relativeTo: nil )
249254 }
@@ -542,6 +547,9 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
542547 // TODO: should be `checkResourceIsReachableAndReturnError` with autoreleased error parameter.
543548 // Currently Autoreleased pointers is not supported on Linux.
544549 open func checkResourceIsReachable( ) throws -> Bool {
550+ #if os(WASI)
551+ return false
552+ #else
545553 guard isFileURL,
546554 let path = path else {
547555 throw NSError ( domain: NSCocoaErrorDomain,
@@ -557,6 +565,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
557565 }
558566
559567 return true
568+ #endif
560569 }
561570
562571 /* 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.
@@ -760,7 +769,7 @@ extension NSString {
760769}
761770
762771extension NSURL {
763-
772+
764773 /* The following methods work on the path portion of a URL in the same manner that the NSPathUtilities methods on NSString do.
765774 */
766775 open class func fileURL( withPathComponents components: [ String ] ) -> URL ? {
@@ -841,6 +850,9 @@ extension NSURL {
841850
842851 open func appendingPathComponent( _ pathComponent: String ) -> URL ? {
843852 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)
844856 // Since we are appending to a URL, path seperators should
845857 // always be '/', even if we're on Windows
846858 if !pathComponent. hasSuffix ( " / " ) && isFileURL {
@@ -852,6 +864,7 @@ extension NSURL {
852864 }
853865
854866 }
867+ #endif
855868 return result
856869 }
857870
@@ -870,15 +883,15 @@ extension NSURL {
870883 open var deletingPathExtension : URL ? {
871884 return CFURLCreateCopyDeletingPathExtension ( kCFAllocatorSystemDefault, _cfObject) ? . _swiftObject
872885 }
873-
886+
874887 /* The following methods work only on `file:` scheme URLs; for non-`file:` scheme URLs, these methods return the URL unchanged.
875888 */
876889 open var standardizingPath : URL ? {
877890 // Documentation says it should expand initial tilde, but it does't do this on OS X.
878891 // In remaining cases it works just like URLByResolvingSymlinksInPath.
879892 return _resolveSymlinksInPath ( excludeSystemDirs: true , preserveDirectoryFlag: true )
880893 }
881-
894+
882895 open var resolvingSymlinksInPath : URL ? {
883896 return _resolveSymlinksInPath ( excludeSystemDirs: true )
884897 }
@@ -896,8 +909,12 @@ extension NSURL {
896909 if selfPath. isAbsolutePath {
897910 absolutePath = selfPath
898911 } else {
912+ #if os(WASI)
913+ return nil
914+ #else
899915 let workingDir = FileManager . default. currentDirectoryPath
900916 absolutePath = workingDir. _bridgeToObjectiveC ( ) . appendingPathComponent ( selfPath)
917+ #endif
901918 }
902919
903920
@@ -918,15 +935,20 @@ extension NSURL {
918935
919936 default :
920937 resolvedPath = resolvedPath. _bridgeToObjectiveC ( ) . appendingPathComponent ( component)
938+ #if !os(WASI)
921939 if let destination = FileManager . default. _tryToResolveTrailingSymlinkInPath ( resolvedPath) {
922940 resolvedPath = destination
923941 }
942+ #endif
924943 }
925944 }
926945
927946 // It might be a responsibility of NSURL(fileURLWithPath:). Check it.
928947 var isExistingDirectory : ObjCBool = false
948+
949+ #if !os(WASI)
929950 let _ = FileManager . default. fileExists ( atPath: resolvedPath, isDirectory: & isExistingDirectory)
951+ #endif
930952
931953 if excludeSystemDirs {
932954 resolvedPath = resolvedPath. _tryToRemovePathPrefix ( " /private " ) ?? resolvedPath
@@ -1005,6 +1027,7 @@ extension NSURL : _StructTypeBridgeable {
10051027
10061028// -----
10071029
1030+ #if !os(WASI)
10081031internal func _CFSwiftURLCopyResourcePropertyForKey( _ url: CFTypeRef , _ key: CFString , _ valuePointer: UnsafeMutablePointer < Unmanaged < CFTypeRef > ? > ? , _ errorPointer: UnsafeMutablePointer < Unmanaged < CFError > ? > ? ) -> _DarwinCompatibleBoolean {
10091032 do {
10101033 let key = URLResourceKey ( rawValue: key. _swiftObject)
@@ -1538,6 +1561,7 @@ fileprivate extension URLResourceValuesStorage {
15381561 }
15391562 }
15401563}
1564+ #endif
15411565
15421566// -----
15431567
0 commit comments