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 @@ -533,9 +533,9 @@ open class FileManager : NSObject {
533
533
#elseif os(Linux) || os(Android) || CYGWIN
534
534
let modeT = number. uint32Value
535
535
#endif
536
- _fileSystemRepresentation ( withPath: path, {
537
- if chmod ( $0, mode_t ( modeT) ) != 0 {
538
- fatalError ( " errno \ ( errno) " )
536
+ try _fileSystemRepresentation ( withPath: path, {
537
+ guard chmod ( $0, mode_t ( modeT) ) == 0 else {
538
+ throw _NSErrorWithErrno ( errno, reading : false , path : path )
539
539
}
540
540
} )
541
541
} 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