lib/fs: Check events against both the user and eval root (#6013)

This commit is contained in:
Simon Frei
2019-09-22 09:03:22 +02:00
committed by Jakob Borg
parent 7127c13f18
commit 35b699dc77
6 changed files with 62 additions and 37 deletions

View File

@@ -60,14 +60,16 @@ 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, *ErrWatchEventOutsideRoot) {
if absPath+string(PathSeparator) == root {
return ".", nil
func (f *BasicFilesystem) unrootedChecked(absPath string, roots []string) (string, *ErrWatchEventOutsideRoot) {
for _, root := range roots {
if absPath+string(PathSeparator) == root {
return ".", nil
}
if strings.HasPrefix(absPath, root) {
return rel(absPath, root), nil
}
}
if !strings.HasPrefix(absPath, root) {
return "", f.newErrWatchEventOutsideRoot(absPath, root)
}
return rel(absPath, root), nil
return "", f.newErrWatchEventOutsideRoot(absPath, roots)
}
func rel(path, prefix string) string {
@@ -78,16 +80,16 @@ 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) {
func (f *BasicFilesystem) watchPaths(name string) (string, []string, error) {
root, err := evalSymlinks(f.root)
if err != nil {
return "", "", err
return "", nil, err
}
absName, err := rooted(name, root)
if err != nil {
return "", "", err
return "", nil, err
}
return filepath.Join(absName, "..."), root, nil
return filepath.Join(absName, "..."), []string{root}, nil
}