(t *testing.T, fsType FilesystemType, uri string)
| 87 | } |
| 88 | |
| 89 | func testWalkInfiniteRecursion(t *testing.T, fsType FilesystemType, uri string) { |
| 90 | if !build.IsWindows { |
| 91 | t.Skip("Infinite recursion detection is tested on windows only") |
| 92 | } |
| 93 | |
| 94 | fs := NewFilesystem(fsType, uri, new(OptionJunctionsAsDirs)) |
| 95 | |
| 96 | if err := fs.MkdirAll("target/foo", 0); err != nil { |
| 97 | t.Fatal(err) |
| 98 | } |
| 99 | if err := fs.Mkdir("towalk", 0); err != nil { |
| 100 | t.Fatal(err) |
| 101 | } |
| 102 | if err := createDirJunct(filepath.Join(uri, "target"), filepath.Join(uri, "towalk/dirjunct")); err != nil { |
| 103 | t.Fatal(err) |
| 104 | } |
| 105 | if err := createDirJunct(filepath.Join(uri, "towalk"), filepath.Join(uri, "target/foo/recurse")); err != nil { |
| 106 | t.Fatal(err) |
| 107 | } |
| 108 | dirjunctCnt := 0 |
| 109 | fooCnt := 0 |
| 110 | found := false |
| 111 | if err := fs.Walk("towalk", func(path string, info FileInfo, err error) error { |
| 112 | if err != nil { |
| 113 | if errors.Is(err, ErrInfiniteRecursion) { |
| 114 | if found { |
| 115 | t.Fatal("second infinite recursion detected at", path) |
| 116 | } |
| 117 | found = true |
| 118 | return nil |
| 119 | } |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | if info.Name() == "dirjunct" { |
| 123 | dirjunctCnt++ |
| 124 | } else if info.Name() == "foo" { |
| 125 | fooCnt++ |
| 126 | } |
| 127 | return nil |
| 128 | }); err != nil { |
| 129 | t.Fatal(err) |
| 130 | } |
| 131 | if dirjunctCnt != 2 || fooCnt != 1 || !found { |
| 132 | t.Fatal("Infinite recursion not detected correctly") |
| 133 | } |
| 134 | } |
no test coverage detected