@@ -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,50 @@ 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
+ let source = " This is the source file "
1082
+ try ? fm. removeItem ( at: srcFile)
1083
+ try source. write ( toFile: srcFile. path, atomically: false , encoding: . utf8)
1084
+
1085
+ func testCopy( ) throws {
1086
+ try ? fm. removeItem ( at: destFile)
1087
+ try fm. copyItem ( at: srcFile, to: destFile)
1088
+ let copy = try String ( contentsOf: destFile)
1089
+ XCTAssertEqual ( source, copy)
1090
+ if let srcPerms = ( try fm. attributesOfItem ( atPath: srcFile. path) [ . posixPermissions] as? NSNumber ) ? . intValue,
1091
+ let destPerms = ( try fm. attributesOfItem ( atPath: destFile. path) [ . posixPermissions] as? NSNumber ) ? . intValue {
1092
+ XCTAssertEqual ( srcPerms, destPerms)
1093
+ } else {
1094
+ XCTFail ( " Cant get file permissions " )
1095
+ }
1096
+ }
1097
+
1098
+ try testCopy ( )
1099
+
1100
+ try fm. setAttributes ( [ . posixPermissions: 0o417 ] , ofItemAtPath: srcFile. path)
1101
+ try testCopy ( )
1102
+
1103
+ try fm. setAttributes ( [ . posixPermissions: 0o400 ] , ofItemAtPath: srcFile. path)
1104
+ try testCopy ( )
1105
+
1106
+ try fm. setAttributes ( [ . posixPermissions: 0o700 ] , ofItemAtPath: srcFile. path)
1107
+ try testCopy ( )
1108
+
1109
+ try fm. setAttributes ( [ . posixPermissions: 0o707 ] , ofItemAtPath: srcFile. path)
1110
+ try testCopy ( )
1111
+
1112
+ try fm. setAttributes ( [ . posixPermissions: 0o411 ] , ofItemAtPath: srcFile. path)
1113
+ try testCopy ( )
1114
+ }
1070
1115
1071
1116
#if !DEPLOYMENT_RUNTIME_OBJC // XDG tests require swift-corelibs-foundation
1072
1117
0 commit comments