(path string)
| 23 | ) |
| 24 | |
| 25 | func greatestExistingAncestor(path string) (string, error) { |
| 26 | if path == string(filepath.Separator) || |
| 27 | path == fmt.Sprintf("%s%s", filepath.VolumeName(path), string(filepath.Separator)) { |
| 28 | return "", fmt.Errorf("cannot watch root directory") |
| 29 | } |
| 30 | |
| 31 | _, err := os.Stat(path) |
| 32 | if err != nil && !os.IsNotExist(err) { |
| 33 | return "", fmt.Errorf("os.Stat(%q): %w", path, err) |
| 34 | } |
| 35 | |
| 36 | if os.IsNotExist(err) { |
| 37 | return greatestExistingAncestor(filepath.Dir(path)) |
| 38 | } |
| 39 | |
| 40 | return path, nil |
| 41 | } |