From 79360e220597d6b1d2e3af1fa5a226c02324218a Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Wed, 10 Apr 2019 22:36:37 +0200 Subject: [PATCH] lib/fs: Add test that symlinks are skipped on walk (#5644) --- lib/fs/basicfs_test.go | 6 ++++++ lib/fs/walkfs_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 lib/fs/walkfs_test.go diff --git a/lib/fs/basicfs_test.go b/lib/fs/basicfs_test.go index dd91aac76..7c14b6b02 100644 --- a/lib/fs/basicfs_test.go +++ b/lib/fs/basicfs_test.go @@ -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) +} diff --git a/lib/fs/walkfs_test.go b/lib/fs/walkfs_test.go new file mode 100644 index 000000000..b09cbf76a --- /dev/null +++ b/lib/fs/walkfs_test.go @@ -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) + } +}