|
|
@@ -156,17 +156,19 @@ func (f *BasicFilesystem) Roots() ([]string, error) {
|
|
|
// unrooted) or an error if the given path is not a subpath and handles the
|
|
|
// special case when the given path is the folder root without a trailing
|
|
|
// pathseparator.
|
|
|
-func (f *BasicFilesystem) unrootedChecked(absPath, root string) (string, error) {
|
|
|
+func (f *BasicFilesystem) unrootedChecked(absPath string, roots []string) (string, error) {
|
|
|
absPath = f.resolveWin83(absPath)
|
|
|
lowerAbsPath := UnicodeLowercase(absPath)
|
|
|
- lowerRoot := UnicodeLowercase(root)
|
|
|
- if lowerAbsPath+string(PathSeparator) == lowerRoot {
|
|
|
- return ".", nil
|
|
|
- }
|
|
|
- if !strings.HasPrefix(lowerAbsPath, lowerRoot) {
|
|
|
- return "", f.newErrWatchEventOutsideRoot(lowerAbsPath, lowerRoot)
|
|
|
+ for _, root := range roots {
|
|
|
+ lowerRoot := UnicodeLowercase(root)
|
|
|
+ if lowerAbsPath+string(PathSeparator) == lowerRoot {
|
|
|
+ return ".", nil
|
|
|
+ }
|
|
|
+ if strings.HasPrefix(lowerAbsPath, lowerRoot) {
|
|
|
+ return rel(absPath, root), nil
|
|
|
+ }
|
|
|
}
|
|
|
- return rel(absPath, root), nil
|
|
|
+ return "", f.newErrWatchEventOutsideRoot(lowerAbsPath, roots)
|
|
|
}
|
|
|
|
|
|
func rel(path, prefix string) string {
|
|
|
@@ -294,10 +296,10 @@ func evalSymlinks(in string) (string, error) {
|
|
|
|
|
|
// 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) {
|
|
|
+func (f *BasicFilesystem) watchPaths(name string) (string, []string, error) {
|
|
|
root, err := evalSymlinks(f.root)
|
|
|
if err != nil {
|
|
|
- return "", "", err
|
|
|
+ return "", nil, err
|
|
|
}
|
|
|
|
|
|
// Remove `\\?\` prefix if the path is just a drive letter as a dirty
|
|
|
@@ -308,11 +310,17 @@ func (f *BasicFilesystem) watchPaths(name string) (string, string, error) {
|
|
|
|
|
|
absName, err := rooted(name, root)
|
|
|
if err != nil {
|
|
|
- return "", "", err
|
|
|
+ return "", nil, err
|
|
|
}
|
|
|
|
|
|
- root = f.resolveWin83(root)
|
|
|
+ roots := []string{f.resolveWin83(root)}
|
|
|
absName = f.resolveWin83(absName)
|
|
|
|
|
|
- return filepath.Join(absName, "..."), root, nil
|
|
|
+ // Events returned from fs watching are all over the place, so allow
|
|
|
+ // both the user's input and the result of "canonicalizing" the path.
|
|
|
+ if roots[0] != f.root {
|
|
|
+ roots = append(roots, f.root)
|
|
|
+ }
|
|
|
+
|
|
|
+ return filepath.Join(absName, "..."), roots, nil
|
|
|
}
|