@@ -487,6 +487,11 @@ contents don't matter for this test
487
487
}
488
488
489
489
func TestWalk (t * testing.T ) {
490
+ // The root of the walk must be a name with an actual basename, not just ".".
491
+ // Walk uses Lstat to obtain the name of the root, and Lstat on platforms
492
+ // other than Plan 9 reports the name "." instead of the actual base name of
493
+ // the directory. (See https://golang.org/issue/42115.)
494
+
490
495
type file struct {
491
496
path string
492
497
name string
@@ -502,62 +507,62 @@ func TestWalk(t *testing.T) {
502
507
}{
503
508
{"no overlay" , `
504
509
{}
505
- -- file.txt --
510
+ -- dir/ file.txt --
506
511
` ,
507
- ". " ,
512
+ "dir " ,
508
513
[]file {
509
- {". " , ". " , 0 , fs .ModeDir | 0700 , true },
510
- {"file.txt" , "file.txt" , 0 , 0600 , false },
514
+ {"dir " , "dir " , 0 , fs .ModeDir | 0700 , true },
515
+ {"dir/ file.txt" , "file.txt" , 0 , 0600 , false },
511
516
},
512
517
},
513
518
{"overlay with different file" , `
514
519
{
515
520
"Replace": {
516
- "file.txt": "other.txt"
521
+ "dir/ file.txt": "dir/ other.txt"
517
522
}
518
523
}
519
- -- file.txt --
520
- -- other.txt --
524
+ -- dir/ file.txt --
525
+ -- dir/ other.txt --
521
526
contents of other file
522
527
` ,
523
- ". " ,
528
+ "dir " ,
524
529
[]file {
525
- {". " , ". " , 0 , fs .ModeDir | 0500 , true },
526
- {"file.txt" , "file.txt" , 23 , 0600 , false },
527
- {"other.txt" , "other.txt" , 23 , 0600 , false },
530
+ {"dir " , "dir " , 0 , fs .ModeDir | 0500 , true },
531
+ {"dir/ file.txt" , "file.txt" , 23 , 0600 , false },
532
+ {"dir/ other.txt" , "other.txt" , 23 , 0600 , false },
528
533
},
529
534
},
530
535
{"overlay with new file" , `
531
536
{
532
537
"Replace": {
533
- "file.txt": "other.txt"
538
+ "dir/ file.txt": "dir/ other.txt"
534
539
}
535
540
}
536
- -- other.txt --
541
+ -- dir/ other.txt --
537
542
contents of other file
538
543
` ,
539
- ". " ,
544
+ "dir " ,
540
545
[]file {
541
- {". " , ". " , 0 , fs .ModeDir | 0500 , true },
542
- {"file.txt" , "file.txt" , 23 , 0600 , false },
543
- {"other.txt" , "other.txt" , 23 , 0600 , false },
546
+ {"dir " , "dir " , 0 , fs .ModeDir | 0500 , true },
547
+ {"dir/ file.txt" , "file.txt" , 23 , 0600 , false },
548
+ {"dir/ other.txt" , "other.txt" , 23 , 0600 , false },
544
549
},
545
550
},
546
551
{"overlay with new directory" , `
547
552
{
548
553
"Replace": {
549
- "dir/file.txt": "other.txt"
554
+ "dir/subdir/ file.txt": "dir/ other.txt"
550
555
}
551
556
}
552
- -- other.txt --
557
+ -- dir/ other.txt --
553
558
contents of other file
554
559
` ,
555
- ". " ,
560
+ "dir " ,
556
561
[]file {
557
- {"." , "." , 0 , fs .ModeDir | 0500 , true },
558
562
{"dir" , "dir" , 0 , fs .ModeDir | 0500 , true },
559
- {"dir" + string (filepath .Separator ) + "file.txt" , "file.txt" , 23 , 0600 , false },
560
- {"other.txt" , "other.txt" , 23 , 0600 , false },
563
+ {"dir/other.txt" , "other.txt" , 23 , 0600 , false },
564
+ {"dir/subdir" , "subdir" , 0 , fs .ModeDir | 0500 , true },
565
+ {"dir/subdir/file.txt" , "file.txt" , 23 , 0600 , false },
561
566
},
562
567
},
563
568
}
@@ -576,8 +581,9 @@ contents of other file
576
581
t .Errorf ("Walk: saw %#v in walk; want %#v" , got , tc .wantFiles )
577
582
}
578
583
for i := 0 ; i < len (got ) && i < len (tc .wantFiles ); i ++ {
579
- if got [i ].path != tc .wantFiles [i ].path {
580
- t .Errorf ("path of file #%v in walk, got %q, want %q" , i , got [i ].path , tc .wantFiles [i ].path )
584
+ wantPath := filepath .FromSlash (tc .wantFiles [i ].path )
585
+ if got [i ].path != wantPath {
586
+ t .Errorf ("path of file #%v in walk, got %q, want %q" , i , got [i ].path , wantPath )
581
587
}
582
588
if got [i ].name != tc .wantFiles [i ].name {
583
589
t .Errorf ("name of file #%v in walk, got %q, want %q" , i , got [i ].name , tc .wantFiles [i ].name )
@@ -603,24 +609,24 @@ func TestWalk_SkipDir(t *testing.T) {
603
609
initOverlay (t , `
604
610
{
605
611
"Replace": {
606
- "skipthisdir /file.go": "dummy.txt",
607
- "dontskip/file.go": "dummy.txt",
608
- "dontskip/skip/file.go": "dummy.txt"
612
+ "dir/skip /file.go": "dummy.txt",
613
+ "dir/ dontskip/file.go": "dummy.txt",
614
+ "dir/ dontskip/skip/file.go": "dummy.txt"
609
615
}
610
616
}
611
617
-- dummy.txt --
612
618
` )
613
619
614
620
var seen []string
615
- Walk (". " , func (path string , info fs.FileInfo , err error ) error {
616
- seen = append (seen , path )
617
- if path == "skipthisdir" || path == filepath . Join ( "dontskip" , " skip") {
621
+ Walk ("dir " , func (path string , info fs.FileInfo , err error ) error {
622
+ seen = append (seen , filepath . ToSlash ( path ) )
623
+ if info . Name () == "skip" {
618
624
return filepath .SkipDir
619
625
}
620
626
return nil
621
627
})
622
628
623
- wantSeen := []string {". " , "dontskip" , filepath . Join ( " dontskip" , " file.go"), filepath . Join ( " dontskip" , " skip") , "dummy.txt" , "skipthisdir " }
629
+ wantSeen := []string {"dir " , "dir/ dontskip" , "dir/ dontskip/ file.go", "dir/ dontskip/ skip" , "dir/skip " }
624
630
625
631
if len (seen ) != len (wantSeen ) {
626
632
t .Errorf ("paths seen in walk: got %v entries; want %v entries" , len (seen ), len (wantSeen ))
@@ -675,8 +681,8 @@ func TestWalk_Symlink(t *testing.T) {
675
681
wantFiles []string
676
682
}{
677
683
{"control" , "dir" , []string {"dir" , "dir" + string (filepath .Separator ) + "file" }},
678
- // ensure Walk doesn't wolk into the directory pointed to by the symlink
679
- // (because it's supposed to use Lstat instead of Stat.
684
+ // ensure Walk doesn't walk into the directory pointed to by the symlink
685
+ // (because it's supposed to use Lstat instead of Stat) .
680
686
{"symlink_to_dir" , "symlink" , []string {"symlink" }},
681
687
{"overlay_to_symlink_to_dir" , "overlay_symlink" , []string {"overlay_symlink" }},
682
688
}
0 commit comments