From dfbbb286fcb1d8c17da2514eb08c2c5a8380cd99 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sat, 11 May 2019 10:06:04 +0200 Subject: [PATCH] lib/fs: Consider win83 for root path as well when watching (ref #5706) (#5709) --- lib/fs/basicfs_unix.go | 16 ++++++++++++++++ lib/fs/basicfs_watch.go | 24 ------------------------ lib/fs/basicfs_windows.go | 25 +++++++++++++++++++++++++ lib/fs/basicfs_windows_test.go | 8 ++++++++ 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/lib/fs/basicfs_unix.go b/lib/fs/basicfs_unix.go index 814093a5f..edbbff086 100644 --- a/lib/fs/basicfs_unix.go +++ b/lib/fs/basicfs_unix.go @@ -76,3 +76,19 @@ func rel(path, prefix string) string { } var evalSymlinks = filepath.EvalSymlinks + +// watchPaths adjust the folder root for use with the notify backend and the +// corresponding absolute path to be passed to notify to watch name. +func (f *BasicFilesystem) watchPaths(name string) (string, string, error) { + root, err := evalSymlinks(f.root) + if err != nil { + return "", "", err + } + + absName, err := rooted(name, root) + if err != nil { + return "", "", err + } + + return filepath.Join(absName, "..."), root, nil +} diff --git a/lib/fs/basicfs_watch.go b/lib/fs/basicfs_watch.go index 252d217bc..796025273 100644 --- a/lib/fs/basicfs_watch.go +++ b/lib/fs/basicfs_watch.go @@ -11,8 +11,6 @@ package fs import ( "context" "errors" - "path/filepath" - "runtime" "github.com/syncthing/notify" ) @@ -57,28 +55,6 @@ func (f *BasicFilesystem) Watch(name string, ignore Matcher, ctx context.Context return outChan, nil } -// watchPaths adjust the folder root for use with the notify backend and the -// corresponding absolute path to be passed to notify to watch name. -func (f *BasicFilesystem) watchPaths(name string) (string, string, error) { - root, err := evalSymlinks(f.root) - if err != nil { - return "", "", err - } - - // Remove `\\?\` prefix if the path is just a drive letter as a dirty - // fix for https://github.com/syncthing/syncthing/issues/5578 - if runtime.GOOS == "windows" && filepath.Clean(name) == "." && len(root) <= 7 && len(root) > 4 && root[:4] == `\\?\` { - root = root[4:] - } - - absName, err := rooted(name, root) - if err != nil { - return "", "", err - } - - return filepath.Join(absName, "..."), root, nil -} - func (f *BasicFilesystem) watchLoop(name, evalRoot string, backendChan chan notify.EventInfo, outChan chan<- Event, ignore Matcher, ctx context.Context) { for { // Detect channel overflow diff --git a/lib/fs/basicfs_windows.go b/lib/fs/basicfs_windows.go index ad44b7bba..66a3c75b7 100644 --- a/lib/fs/basicfs_windows.go +++ b/lib/fs/basicfs_windows.go @@ -222,3 +222,28 @@ func evalSymlinks(in string) (string, error) { } return longFilenameSupport(out), nil } + +// watchPaths adjust the folder root for use with the notify backend and the +// corresponding absolute path to be passed to notify to watch name. +func (f *BasicFilesystem) watchPaths(name string) (string, string, error) { + root, err := evalSymlinks(f.root) + if err != nil { + return "", "", err + } + + // Remove `\\?\` prefix if the path is just a drive letter as a dirty + // fix for https://github.com/syncthing/syncthing/issues/5578 + if filepath.Clean(name) == "." && len(root) <= 7 && len(root) > 4 && root[:4] == `\\?\` { + root = root[4:] + } + + absName, err := rooted(name, root) + if err != nil { + return "", "", err + } + + root = f.resolveWin83(root) + absName = f.resolveWin83(absName) + + return filepath.Join(absName, "..."), root, nil +} diff --git a/lib/fs/basicfs_windows_test.go b/lib/fs/basicfs_windows_test.go index c009c7744..8a753491f 100644 --- a/lib/fs/basicfs_windows_test.go +++ b/lib/fs/basicfs_windows_test.go @@ -44,6 +44,10 @@ func TestWindowsPaths(t *testing.T) { func TestResolveWindows83(t *testing.T) { fs, dir := setup(t) + if isMaybeWin83(dir) { + dir = fs.resolveWin83(dir) + fs = newBasicFilesystem(dir) + } defer os.RemoveAll(dir) shortAbs, _ := fs.rooted("LFDATA~1") @@ -71,6 +75,10 @@ func TestResolveWindows83(t *testing.T) { func TestIsWindows83(t *testing.T) { fs, dir := setup(t) + if isMaybeWin83(dir) { + dir = fs.resolveWin83(dir) + fs = newBasicFilesystem(dir) + } defer os.RemoveAll(dir) tempTop, _ := fs.rooted(TempName("baz"))