Skip to content

Commit e3b9b73

Browse files
authored
Merge pull request #1905 from spevans/pr_set_attributes_chmod_50
2 parents 0c9e76b + 04ff380 commit e3b9b73

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Foundation/FileManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,9 @@ open class FileManager : NSObject {
524524
#elseif os(Linux) || os(Android) || CYGWIN
525525
let modeT = number.uint32Value
526526
#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)
530530
}
531531
})
532532
} else {

TestFoundation/TestFileManager.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ class TestFileManager : XCTestCase {
434434
} catch {
435435
XCTFail("Failed to clean up files")
436436
}
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+
}
437446
}
438447

439448
func test_pathEnumerator() {

0 commit comments

Comments
 (0)