Skip to content

Commit e3434be

Browse files
authored
Merge pull request #1901 from spevans/pr_set_attributes_chmod
2 parents fcc46b0 + 5995272 commit e3434be

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
@@ -533,9 +533,9 @@ open class FileManager : NSObject {
533533
#elseif os(Linux) || os(Android) || CYGWIN
534534
let modeT = number.uint32Value
535535
#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)
539539
}
540540
})
541541
} 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)