lib/fs, lib/model: Add error channel to Watch to avoid panics (fixes #5697) (#5734)

* lib/fs, lib/model: Add error channel to Watch to avoid panics (fixes #5697)

* forgot unsupported watch

* and more non(-standard)-unixy fixes

* and windows test

* review
This commit is contained in:
Simon Frei
2019-05-25 21:08:26 +02:00
committed by Audrius Butkevicius
parent 9e6db72535
commit 486230768e
12 changed files with 158 additions and 105 deletions

View File

@@ -9,7 +9,6 @@
package fs
import (
"fmt"
"os"
"path/filepath"
"strings"
@@ -58,17 +57,17 @@ func (f *BasicFilesystem) Roots() ([]string, error) {
}
// unrootedChecked returns the path relative to the folder root (same as
// unrooted). It panics if the given path is not a subpath and handles the
// 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 {
func (f *BasicFilesystem) unrootedChecked(absPath, root string) (string, *ErrWatchEventOutsideRoot) {
if absPath+string(PathSeparator) == root {
return "."
return ".", nil
}
if !strings.HasPrefix(absPath, root) {
panic(fmt.Sprintf("bug: Notify backend is processing a change outside of the filesystem root: f.root==%v, root==%v, path==%v", f.root, root, absPath))
return "", f.newErrWatchEventOutsideRoot(absPath, root)
}
return rel(absPath, root)
return rel(absPath, root), nil
}
func rel(path, prefix string) string {