scan: skip OS default excludes, and record nothing on filesystems that are not persistent (closes #124)
check / check (push) Waiting to run
check / check (push) Waiting to run
scan never records or reads anything on a filesystem that is not persistent (tmpfs, proc, sysfs and the like), however it reaches it; no flag turns this off. It notes each such filesystem's device ID as it starts: on Linux from /proc/self/mountinfo, on macOS by lstat of each listed mount point. Below an operand the walk also skips the default excludes, a path list per system (Linux, macOS, and Windows, not used yet); --no-default-excludes turns off only those. A default exclude that is itself an operand gets no skip line. The tests stop at once, saying why, when TMPDIR is not on a persistent filesystem. Judgement call: an unreadable mount list fails the scan, and no flag gets round it. Judgement call: a file on such a filesystem below an operand gets the same line as a directory. Judgement call: such an operand that another operand's walk also reaches is named twice. Unverified: whether macOS's mount list gives the device lstat reports, so macOS keeps lstat, and a hidden mount there can still add another filesystem's device. Unverified: the macOS code is never built or run here; bind mounts need root to test. Model: opus-5-5
This commit is contained in:
+32
-1
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
@@ -18,6 +19,36 @@ import (
|
||||
// error prints and a runtime failure must not.
|
||||
const usageMarker = "Usage:"
|
||||
|
||||
// TestMain stops the tests at once, saying why, when their temporary
|
||||
// directory is not on a persistent filesystem: scan records nothing
|
||||
// there (README "Rules for the walk"), so most scan tests would fail
|
||||
// without saying why.
|
||||
func TestMain(m *testing.M) {
|
||||
nonPersistent, err := nonPersistentFilesystems()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "list the mounted filesystems: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dir := os.TempDir()
|
||||
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dev, ok := deviceOfInfo(fi)
|
||||
if fsType, found := nonPersistent[dev]; ok && found {
|
||||
fmt.Fprintf(os.Stderr, "%s is on %s, not a persistent filesystem, "+
|
||||
"and scan records nothing there: set TMPDIR to a directory on a "+
|
||||
"persistent filesystem\n", dir, fsType)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
// walSuffixes are the SQLite sidecar files a WAL-mode database keeps
|
||||
// while it is open. A clean close checkpoints the WAL and removes
|
||||
// both; finding either afterwards means the database was never closed.
|
||||
@@ -535,7 +566,7 @@ func TestRunNamesDefaultDatabase(t *testing.T) {
|
||||
}{
|
||||
cmdScan: {
|
||||
run: func() error {
|
||||
return runScan(t.Context(), []string{missing}, 1, false)
|
||||
return runScan(t.Context(), []string{missing}, 1, false, false)
|
||||
},
|
||||
want: scanWant,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user