diff options
author | Jakob Borg <jakob@nym.se> | 2016-06-26 10:17:20 +0000 |
---|---|---|
committer | Audrius Butkevicius <audrius.butkevicius@gmail.com> | 2016-06-26 10:17:20 +0000 |
commit | b0d03d1f1c01126332c4455359dd048ee9f292fd (patch) | |
tree | a925341a74ef0b8dbe427e3ca952ae17d5e7ee1e | |
parent | a2dcffcca2f425d84ca45a1e7f4a67cc785cb65d (diff) |
lib/config: Retain slash at end of path after expanding ~ (fixes #2782)
The various path cleaning operations done in in cleanedPath() removes
it, so we make sure it's added again at the end. This makes adding the
slash in prepare() unnecessary, but keep it anyway for display purposes
(people looking at the config).
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3342
-rw-r--r-- | lib/config/folderconfiguration.go | 6 | ||||
-rw-r--r-- | lib/model/model_test.go | 49 |
2 files changed, 55 insertions, 0 deletions
diff --git a/lib/config/folderconfiguration.go b/lib/config/folderconfiguration.go index 75a984c6d..5782d0ed6 100644 --- a/lib/config/folderconfiguration.go +++ b/lib/config/folderconfiguration.go @@ -168,6 +168,12 @@ func (f *FolderConfiguration) cleanedPath() string { return `\\?\` + cleaned } + // If we're not on Windows, we want the path to end with a slash to + // penetrate symlinks. On Windows, paths must not end with a slash. + if runtime.GOOS != "windows" && cleaned[len(cleaned)-1] != filepath.Separator { + cleaned = cleaned + string(filepath.Separator) + } + return cleaned } diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 4a453565b..0a8a47a9d 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -28,6 +28,7 @@ import ( "github.com/syncthing/syncthing/lib/ignore" "github.com/syncthing/syncthing/lib/osutil" "github.com/syncthing/syncthing/lib/protocol" + srand "github.com/syncthing/syncthing/lib/rand" ) var device1, device2 protocol.DeviceID @@ -1507,6 +1508,54 @@ func TestScanNoDatabaseWrite(t *testing.T) { } } +func TestIssue2782(t *testing.T) { + // CheckFolderHealth should accept a symlinked folder, when using tilde-expanded path. + + if runtime.GOOS == "windows" { + t.Skip("not reliable on Windows") + return + } + home := os.Getenv("HOME") + if home == "" { + t.Skip("no home") + } + + // Create the test env. Needs to be based on $HOME as tilde expansion is + // part of the issue. Skip the test if any of this fails, as we are a + // bit outside of our stated domain here... + + testName := ".syncthing-test." + srand.String(16) + testDir := filepath.Join(home, testName) + if err := osutil.RemoveAll(testDir); err != nil { + t.Skip(err) + } + if err := osutil.MkdirAll(testDir+"/syncdir", 0755); err != nil { + t.Skip(err) + } + if err := ioutil.WriteFile(testDir+"/syncdir/file", []byte("hello, world\n"), 0644); err != nil { + t.Skip(err) + } + if err := os.Symlink("syncdir", testDir+"/synclink"); err != nil { + t.Skip(err) + } + defer osutil.RemoveAll(testDir) + + db := db.OpenMemory() + m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil) + m.AddFolder(config.NewFolderConfiguration("default", "~/"+testName+"/synclink/")) + m.StartFolder("default") + m.ServeBackground() + defer m.Stop() + + if err := m.ScanFolder("default"); err != nil { + t.Error("scan error:", err) + } + + if err := m.CheckFolderHealth("default"); err != nil { + t.Error("health check error:", err) + } +} + type fakeAddr struct{} func (fakeAddr) Network() string { |