@@ -433,10 +433,13 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
433
433
#if os(WASI)
434
434
// WASI does not have permission concept
435
435
let permissions : Int ? = nil
436
+ // ReadingOptions.atomic won't be specified on WASI as it's marked unavailable
437
+ var atomicWrite : Bool { false }
436
438
#else
437
439
let permissions = try ? fm. attributesOfItem ( atPath: path) [ . posixPermissions] as? Int
440
+ let atomicWrite = writeOptionsMask. contains ( . atomic)
438
441
#endif
439
- if writeOptionsMask . contains ( . atomic ) {
442
+ if atomicWrite {
440
443
let ( newFD, auxFilePath) = try _NSCreateTemporaryFile ( path)
441
444
let fh = FileHandle ( fileDescriptor: newFD, closeOnDealloc: true )
442
445
do {
@@ -487,22 +490,38 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
487
490
488
491
/// Writes the data object's bytes to the file specified by a given path.
489
492
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
493
+ #if os(WASI)
494
+ @available ( * , unavailable, message: " WASI does not support atomic file-writing as it does not have temporary directories " )
495
+ #endif
490
496
open func write( toFile path: String , atomically useAuxiliaryFile: Bool ) -> Bool {
497
+ #if os(WASI)
498
+ // WASI does not support atomic file-writing as it does not have temporary directories
499
+ return false
500
+ #else
491
501
do {
492
502
try write ( toFile: path, options: useAuxiliaryFile ? . atomic : [ ] )
493
503
} catch {
494
504
return false
495
505
}
496
506
return true
507
+ #endif
497
508
}
498
509
499
510
/// Writes the data object's bytes to the location specified by a given URL.
500
511
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
512
+ #if os(WASI)
513
+ @available ( * , unavailable, message: " WASI does not support atomic file-writing as it does not have temporary directories " )
514
+ #endif
501
515
open func write( to url: URL , atomically: Bool ) -> Bool {
516
+ #if os(WASI)
517
+ // WASI does not support atomic file-writing as it does not have temporary directories
518
+ return false
519
+ #else
502
520
if url. isFileURL {
503
521
return write ( toFile: url. path, atomically: atomically)
504
522
}
505
523
return false
524
+ #endif
506
525
}
507
526
508
527
/// Writes the data object's bytes to the location specified by a given URL.
0 commit comments