diff --git a/internal/apply/placement_guard.go b/internal/apply/placement_guard.go index 248dda54..09662a6e 100644 --- a/internal/apply/placement_guard.go +++ b/internal/apply/placement_guard.go @@ -386,11 +386,15 @@ func below(path, dir string) bool { // atOrBelow says whether path is dir or below it. func atOrBelow(path, dir string) bool { return path == dir || below(path, dir) } +// evalSymlinks follows the links of an existing path; a variable so a test judges paths whose machine it does not touch (a mount +// of the machine it runs on may not answer). +var evalSymlinks = filepath.EvalSymlinks + // resolved is a path with every link in it followed, as far as the path exists, and the rest as declared. func resolved(path string) string { rest := "" for p := path; ; p = filepath.Dir(p) { - if real, err := filepath.EvalSymlinks(p); err == nil { + if real, err := evalSymlinks(p); err == nil { return filepath.Clean(filepath.Join(real, rest)) } if filepath.Dir(p) == p { diff --git a/internal/apply/placement_guard_test.go b/internal/apply/placement_guard_test.go index 8bff411d..869dddd9 100644 --- a/internal/apply/placement_guard_test.go +++ b/internal/apply/placement_guard_test.go @@ -178,6 +178,11 @@ func TestAFoundDirectoryIsUsedAsFound(t *testing.T) { // The module's own directories keep being placed: below /var/lib, below /etc as root's, a container's mount of // the machine's docker socket. func TestAModulesOwnPlacesAreStillPlaced(t *testing.T) { + // The paths below are judged as written: no link of them is followed on the machine the test runs on, whose mounts of them + // (a share that does not answer) it does not depend on. + was := evalSymlinks + evalSymlinks = func(p string) (string, error) { return p, nil } + t.Cleanup(func() { evalSymlinks = was }) for _, path := range []string{"/var/lib/notes/data", "/etc/systemd/logind.conf.d", "/var/run/fail2ban", "/srv/notes", "/mnt/plex/config", "/storage/media", "/var/lib/mesh/registry"} { if err := refusePath(path, placingDirectory, "notes", ""); err != nil {