diff --git a/core/internal/trash/trash.go b/core/internal/trash/trash.go index f130f8623..3b0b4c0da 100644 --- a/core/internal/trash/trash.go +++ b/core/internal/trash/trash.go @@ -250,6 +250,10 @@ func Put(path string) (Entry, error) { }, nil } +// mountPoints is a variable so tests can keep the mount walk off the real +// filesystem; HOME and XDG_DATA_HOME alone do not redirect it. +var mountPoints = readMountPoints + // allTrashDirs returns the home trash plus every per-mountpoint trash dir // that exists (and passes the spec's safety checks for $topdir/.Trash). func allTrashDirs() []string { @@ -259,7 +263,7 @@ func allTrashDirs() []string { } uid := strconv.Itoa(os.Getuid()) - for _, mount := range readMountPoints() { + for _, mount := range mountPoints() { shared := filepath.Join(mount, ".Trash") if isValidSharedTrash(shared) { candidate := filepath.Join(shared, uid) diff --git a/core/internal/trash/trash_test.go b/core/internal/trash/trash_test.go index fc533564d..04f3c9352 100644 --- a/core/internal/trash/trash_test.go +++ b/core/internal/trash/trash_test.go @@ -17,6 +17,13 @@ func setupHomeTrash(t *testing.T) (homeRoot string, trashDir string) { } t.Setenv("XDG_DATA_HOME", xdg) t.Setenv("HOME", homeRoot) + + // Without this, Count() and Empty() reach the machine's real per-mount + // trash dirs, and Empty() deletes what it finds there. + prev := mountPoints + mountPoints = func() []string { return nil } + t.Cleanup(func() { mountPoints = prev }) + trashDir = filepath.Join(xdg, "Trash") return homeRoot, trashDir }