mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
lib/fs: Add test that symlinks are skipped on walk (#5644)
This commit is contained in:
parent
9b2a73f9ab
commit
79360e2205
@ -566,3 +566,9 @@ func TestRel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBasicWalkSkipSymlink(t *testing.T) {
|
||||||
|
_, dir := setup(t)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
testWalkSkipSymlink(t, FilesystemTypeBasic, dir)
|
||||||
|
}
|
||||||
|
41
lib/fs/walkfs_test.go
Normal file
41
lib/fs/walkfs_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2019 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
package fs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func testWalkSkipSymlink(t *testing.T, fsType FilesystemType, uri string) {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("Symlinks on windows")
|
||||||
|
}
|
||||||
|
|
||||||
|
fs := NewFilesystem(fsType, uri)
|
||||||
|
|
||||||
|
if err := fs.MkdirAll("target/foo", 0755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := fs.Mkdir("towalk", 0755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := fs.CreateSymlink("target", "towalk/symlink"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := fs.Walk("towalk", func(path string, info FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if info.Name() != "symlink" && info.Name() != "towalk" {
|
||||||
|
t.Fatal("Walk unexpected file", info.Name())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user