@@ -496,15 +496,18 @@ class TestFileManager : XCTestCase {
496
496
func test_directoryEnumerator( ) {
497
497
let fm = FileManager . default
498
498
let basePath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) / "
499
- let subDirs1 = basePath + " subdir1/subdir2/.hiddenDir/subdir3/ "
499
+ let hiddenDir1 = basePath + " subdir1/subdir2/.hiddenDir/ "
500
+ let subDirs1 = hiddenDir1 + " subdir3/ "
500
501
let itemPath1 = basePath + " itemFile1 "
501
502
#if os(Windows)
502
503
// Filenames ending with '.' are not valid on Windows, so don't bother testing them
503
- let subDirs2 = basePath + " subdir1/subdir2/subdir4.app/subdir5/.subdir6.ext/subdir7.ext/ "
504
+ let hiddenDir2 = basePath + " subdir1/subdir2/subdir4.app/subdir5/.subdir6.ext/ "
505
+ let subDirs2 = hiddenDir2 + " subdir7.ext/ "
504
506
let itemPath2 = subDirs1 + " itemFile2 "
505
507
let itemPath3 = subDirs1 + " itemFile3.ext "
506
508
#else
507
- let subDirs2 = basePath + " subdir1/subdir2/subdir4.app/subdir5./.subdir6.ext/subdir7.ext./ "
509
+ let hiddenDir2 = basePath + " subdir1/subdir2/subdir4.app/subdir5./.subdir6.ext/ "
510
+ let subDirs2 = hiddenDir2 + " subdir7.ext./ "
508
511
let itemPath2 = subDirs1 + " itemFile2. "
509
512
let itemPath3 = subDirs1 + " itemFile3.ext. "
510
513
#endif
@@ -555,10 +558,35 @@ class TestFileManager : XCTestCase {
555
558
556
559
XCTAssertNotNil ( try ? fm. createDirectory ( atPath: subDirs1, withIntermediateDirectories: true , attributes: nil ) )
557
560
XCTAssertNotNil ( try ? fm. createDirectory ( atPath: subDirs2, withIntermediateDirectories: true , attributes: nil ) )
558
- for filename in [ itemPath1, itemPath2, itemPath3, hiddenItem1 , hiddenItem2 , hiddenItem3 , hiddenItem4 ] {
561
+ for filename in [ itemPath1, itemPath2, itemPath3] {
559
562
XCTAssertTrue ( fm. createFile ( atPath: filename, contents: Data ( ) , attributes: nil ) , " Cant create file ' \( filename) ' " )
560
563
}
561
564
565
+ var resourceValues = URLResourceValues ( )
566
+ resourceValues. isHidden = true
567
+ for filename in [ hiddenItem1, hiddenItem2, hiddenItem3, hiddenItem4] {
568
+ XCTAssertTrue ( fm. createFile ( atPath: filename, contents: Data ( ) , attributes: nil ) , " Cant create file ' \( filename) ' " )
569
+ #if os(Windows)
570
+ do {
571
+ var url = URL ( fileURLWithPath: filename)
572
+ try url. setResourceValues ( resourceValues)
573
+ } catch {
574
+ XCTFail ( " Couldn't make \( filename) a hidden file " )
575
+ }
576
+ #endif
577
+ }
578
+
579
+ #if os(Windows)
580
+ do {
581
+ var hiddenURL1 = URL ( fileURLWithPath: hiddenDir1)
582
+ var hiddenURL2 = URL ( fileURLWithPath: hiddenDir2)
583
+ try hiddenURL1. setResourceValues ( resourceValues)
584
+ try hiddenURL2. setResourceValues ( resourceValues)
585
+ } catch {
586
+ XCTFail ( " Couldn't make \( hiddenDir1) and \( hiddenDir2) hidden directories " )
587
+ }
588
+ #endif
589
+
562
590
if let foundItems = directoryItems ( options: [ ] ) {
563
591
XCTAssertEqual ( foundItems. count, fileLevels. count)
564
592
for (name, level) in foundItems {
0 commit comments