File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -524,9 +524,9 @@ open class FileManager : NSObject {
524
524
#elseif os(Linux) || os(Android) || CYGWIN
525
525
let modeT = number. uint32Value
526
526
#endif
527
- _fileSystemRepresentation ( withPath: path, {
528
- if chmod ( $0, mode_t ( modeT) ) != 0 {
529
- fatalError ( " errno \ ( errno) " )
527
+ try _fileSystemRepresentation ( withPath: path, {
528
+ guard chmod ( $0, mode_t ( modeT) ) == 0 else {
529
+ throw _NSErrorWithErrno ( errno, reading : false , path : path )
530
530
}
531
531
} )
532
532
} else {
Original file line number Diff line number Diff line change @@ -434,6 +434,15 @@ class TestFileManager : XCTestCase {
434
434
} catch {
435
435
XCTFail ( " Failed to clean up files " )
436
436
}
437
+
438
+ // test non existant file
439
+ let noSuchFile = NSTemporaryDirectory ( ) + " fileThatDoesntExist "
440
+ try ? fm. removeItem ( atPath: noSuchFile)
441
+ do {
442
+ try fm. setAttributes ( [ . posixPermissions: 0 ] , ofItemAtPath: noSuchFile)
443
+ XCTFail ( " Setting permissions of non-existant file should throw " )
444
+ } catch {
445
+ }
437
446
}
438
447
439
448
func test_pathEnumerator( ) {
You can’t perform that action at this time.
0 commit comments