lib/model, lib/scanner: Properly ignore symlinks on Windows (fixes #4035)

Adds a unit test to ensure we don't scan symlinks on Windows. For the
rwfolder, trusts that the logic in the invalid check is correct and that
the check is actually called from the need loop.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4042
This commit is contained in:
Jakob Borg
2017-03-18 00:25:47 +00:00
committed by Audrius Butkevicius
parent a54365424e
commit 5c27796471
3 changed files with 52 additions and 3 deletions

View File

@@ -280,7 +280,7 @@ func TestIssue1507(t *testing.T) {
fn("", nil, protocol.ErrClosed)
}
func TestWalkSymlink(t *testing.T) {
func TestWalkSymlinkUnix(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping unsupported symlink test")
return
@@ -323,6 +323,45 @@ func TestWalkSymlink(t *testing.T) {
}
}
func TestWalkSymlinkWindows(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("skipping unsupported symlink test")
}
// Create a folder with a symlink in it
os.RemoveAll("_symlinks")
defer os.RemoveAll("_symlinks")
os.Mkdir("_symlinks", 0755)
if err := os.Symlink("destination", "_symlinks/link"); err != nil {
// Probably we require permissions we don't have.
t.Skip(err)
}
// Scan it
fchan, err := Walk(Config{
Dir: "_symlinks",
BlockSize: 128 * 1024,
})
if err != nil {
t.Fatal(err)
}
var files []protocol.FileInfo
for f := range fchan {
files = append(files, f)
}
// Verify that we got zero symlinks
if len(files) != 0 {
t.Errorf("expected zero symlinks, not %d", len(files))
}
}
func walkDir(dir string) ([]protocol.FileInfo, error) {
fchan, err := Walk(Config{
Dir: dir,