@@ -41,6 +41,7 @@ class TestFileManager : XCTestCase {
41
41
( " test_temporaryDirectoryForUser " , test_temporaryDirectoryForUser) ,
42
42
( " test_creatingDirectoryWithShortIntermediatePath " , test_creatingDirectoryWithShortIntermediatePath) ,
43
43
( " test_mountedVolumeURLs " , test_mountedVolumeURLs) ,
44
+ ( " test_copyItemsPermissions " , test_copyItemsPermissions) ,
44
45
]
45
46
46
47
#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
@@ -1067,6 +1068,48 @@ class TestFileManager : XCTestCase {
1067
1068
XCTAssertFalse ( fm. contentsEqual ( atPath: dataFile1. path, andPath: dataFile2. path) )
1068
1069
XCTAssertFalse ( fm. contentsEqual ( atPath: testDir1. path, andPath: testDir2. path) )
1069
1070
}
1071
+
1072
+ func test_copyItemsPermissions( ) throws {
1073
+ let fm = FileManager . default
1074
+ let tmpDir = fm. temporaryDirectory. appendingPathComponent ( " test_copyItemsPermissions " )
1075
+ try fm. createDirectory ( at: tmpDir, withIntermediateDirectories: true )
1076
+ defer { try ? fm. removeItem ( atPath: tmpDir. path) }
1077
+
1078
+ let srcFile = tmpDir. appendingPathComponent ( " file1.txt " )
1079
+ let destFile = tmpDir. appendingPathComponent ( " file2.txt " )
1080
+
1081
+ try ? fm. removeItem ( at: srcFile)
1082
+ try " This is the source file " . write ( toFile: srcFile. path, atomically: false , encoding: . utf8)
1083
+
1084
+ func testCopy( ) throws {
1085
+ try ? fm. removeItem ( at: destFile)
1086
+ try fm. copyItem ( at: srcFile, to: destFile)
1087
+
1088
+ if let srcPerms = ( try fm. attributesOfItem ( atPath: srcFile. path) [ . posixPermissions] as? NSNumber ) ? . intValue,
1089
+ let destPerms = ( try fm. attributesOfItem ( atPath: destFile. path) [ . posixPermissions] as? NSNumber ) ? . intValue {
1090
+ XCTAssertEqual ( srcPerms, destPerms)
1091
+ } else {
1092
+ XCTFail ( " Cant get file permissions " )
1093
+ }
1094
+ }
1095
+
1096
+ try testCopy ( )
1097
+
1098
+ try fm. setAttributes ( [ . posixPermissions: 0o417 ] , ofItemAtPath: srcFile. path)
1099
+ try testCopy ( )
1100
+
1101
+ try fm. setAttributes ( [ . posixPermissions: 0o400 ] , ofItemAtPath: srcFile. path)
1102
+ try testCopy ( )
1103
+
1104
+ try fm. setAttributes ( [ . posixPermissions: 0o700 ] , ofItemAtPath: srcFile. path)
1105
+ try testCopy ( )
1106
+
1107
+ try fm. setAttributes ( [ . posixPermissions: 0o707 ] , ofItemAtPath: srcFile. path)
1108
+ try testCopy ( )
1109
+
1110
+ try fm. setAttributes ( [ . posixPermissions: 0o411 ] , ofItemAtPath: srcFile. path)
1111
+ try testCopy ( )
1112
+ }
1070
1113
1071
1114
#if !DEPLOYMENT_RUNTIME_OBJC // XDG tests require swift-corelibs-foundation
1072
1115
0 commit comments