@@ -563,7 +563,7 @@ class TestFileManager : XCTestCase {
563
563
let fm = FileManager . default
564
564
let srcPath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) "
565
565
let destPath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) "
566
-
566
+
567
567
func cleanup( ) {
568
568
ignoreError { try fm. removeItem ( atPath: srcPath) }
569
569
ignoreError { try fm. removeItem ( atPath: destPath) }
@@ -599,8 +599,13 @@ class TestFileManager : XCTestCase {
599
599
cleanup ( )
600
600
createDirectory ( atPath: srcPath)
601
601
createDirectory ( atPath: " \( srcPath) /tempdir " )
602
+ createDirectory ( atPath: " \( srcPath) /tempdir/subdir " )
603
+ createDirectory ( atPath: " \( srcPath) /tempdir/subdir/otherdir " )
604
+ createDirectory ( atPath: " \( srcPath) /tempdir/subdir/otherdir/extradir " )
602
605
createFile ( atPath: " \( srcPath) /tempdir/tempfile " )
603
606
createFile ( atPath: " \( srcPath) /tempdir/tempfile2 " )
607
+ createFile ( atPath: " \( srcPath) /tempdir/subdir/otherdir/extradir/tempfile2 " )
608
+
604
609
do {
605
610
try fm. copyItem ( atPath: srcPath, toPath: destPath)
606
611
} catch let error {
@@ -610,16 +615,36 @@ class TestFileManager : XCTestCase {
610
615
XCTAssertTrue ( directoryExists ( atPath: " \( destPath) /tempdir " ) )
611
616
XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/tempfile " ) )
612
617
XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/tempfile2 " ) )
613
-
618
+ XCTAssertTrue ( directoryExists ( atPath: " \( destPath) /tempdir/subdir/otherdir/extradir " ) )
619
+ XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/subdir/otherdir/extradir/tempfile2 " ) )
620
+
614
621
if ( false == directoryExists ( atPath: destPath) ) {
615
622
return
616
623
}
617
624
do {
618
625
try fm. copyItem ( atPath: srcPath, toPath: destPath)
626
+ XCTFail ( " Copy overwrites a file/folder that already exists " )
619
627
} catch {
620
- return
628
+ // ignore
629
+ }
630
+
631
+ // Test copying a symlink
632
+ let srcLink = srcPath + " /testlink "
633
+ let destLink = destPath + " /testlink "
634
+ do {
635
+ try fm. createSymbolicLink ( atPath: srcLink, withDestinationPath: " linkdest " )
636
+ try fm. copyItem ( atPath: srcLink, toPath: destLink)
637
+ XCTAssertEqual ( try fm. destinationOfSymbolicLink ( atPath: destLink) , " linkdest " )
638
+ } catch {
639
+ XCTFail ( " \( error) " )
640
+ }
641
+
642
+ do {
643
+ try fm. copyItem ( atPath: srcLink, toPath: destLink)
644
+ XCTFail ( " Creating link where one already exists " )
645
+ } catch {
646
+ // ignore
621
647
}
622
- XCTFail ( " Copy overwrites a file/folder that already exists " )
623
648
}
624
649
625
650
func test_homedirectoryForUser( ) {
0 commit comments