Say "skipped" in scan's warnings for skipped paths (closes #170) (#195)
check / check (push) Successful in 1m29s

This commit was merged in pull request #195.
This commit is contained in:
clawbot committed 2026-11-11 13:37:14 +01:00
1 parent 317abb834c
commit e16c46804d
7 files changed
+97 -48

No files matched your search

+33 -11
View File
@@ -752,8 +752,9 @@ func TestWalkPassesOverRemovedPaths(t *testing.T) {
// TestScanWarnsAboutUnreadablePaths checks that a permission error is
// still warned about and counted as skipped, unlike a removed path. The
// walk reaches an unreadable directory, and a file in a directory that
// can be read but not searched. Another such file is an operand.
// walk reaches an unreadable directory. It also reaches a file and a
// subdirectory in a directory that can be read but not searched. Another
// such file is an operand.
//
//nolint:paralleltest // captureStderr replaces the process-wide os.Stderr
func TestScanWarnsAboutUnreadablePaths(t *testing.T) {
@@ -765,6 +766,7 @@ func TestScanWarnsAboutUnreadablePaths(t *testing.T) {
dir := t.TempDir()
tree := filepath.Join(dir, "tree")
walked := writeFile(t, tree, "unsearchable/f", []byte("x"))
subdir := filepath.Join(filepath.Dir(walked), "d")
operand := writeFile(t, dir, "unsearchable/f", []byte("y"))
unreadable := filepath.Join(tree, "unreadable")
@@ -773,6 +775,11 @@ func TestScanWarnsAboutUnreadablePaths(t *testing.T) {
t.Fatal(err)
}
err = os.Mkdir(subdir, 0o750)
if err != nil {
t.Fatal(err)
}
modes := map[string]fs.FileMode{
unreadable: 0,
filepath.Dir(walked): 0o400,
@@ -793,15 +800,16 @@ func TestScanWarnsAboutUnreadablePaths(t *testing.T) {
}
st := syncTree(t, openTestDB(t), tree, operand)
if st != (scanStats{skipped: 3}) {
t.Errorf("stats = %+v, want 3 skipped and nothing else", st)
if st != (scanStats{skipped: 4}) {
t.Errorf("stats = %+v, want 4 skipped and nothing else", st)
}
got := stderr()
for _, warning := range []string{
"walk " + unreadable + ": open " + unreadable + ": permission denied\n",
"stat " + walked + ": lstat " + walked + ": permission denied\n",
"walk " + operand + ": lstat " + operand + ": permission denied\n",
"scan: skipped " + unreadable + " (permission denied)\n",
"scan: skipped " + walked + " (permission denied)\n",
"scan: skipped " + subdir + " (permission denied)\n",
"scan: skipped " + operand + " (permission denied)\n",
} {
if !strings.Contains(got, warning) {
t.Errorf("stderr = %q, want %q", got, warning)
@@ -1941,14 +1949,19 @@ func TestScanHardlinksReadOnce(t *testing.T) {
}
}
// TestScanHardlinkRunFailsTogether makes a file with two hard links
// unreadable. Both paths are counted as skipped, and each gets its own
// warning.
//
//nolint:paralleltest // captureStderr replaces the process-wide os.Stderr
func TestScanHardlinkRunFailsTogether(t *testing.T) {
t.Parallel()
stderr := captureStderr(t)
dir := t.TempDir()
db := openTestDB(t)
a := writeFile(t, dir, "a.bin", pattern(1, 300))
b := filepath.Join(dir, "b.bin")
err := os.Link(a, filepath.Join(dir, "b.bin"))
err := os.Link(a, b)
if err != nil {
t.Fatal(err)
}
@@ -1964,6 +1977,15 @@ func TestScanHardlinkRunFailsTogether(t *testing.T) {
if st.skipped != 2 || st.added != 0 {
t.Fatalf("stats = %+v, want both hardlink paths skipped", st)
}
got := stderr()
for _, p := range []string{a, b} {
warning := "scan: skipped " + p + " (permission denied)\n"
if !strings.Contains(got, warning) {
t.Errorf("stderr = %q, want %q", got, warning)
}
}
}
// TestHashPhaseSkipsFileReplacedByFIFO replaces a walked regular file
@@ -2001,7 +2023,7 @@ func TestHashPhaseSkipsFileReplacedByFIFO(t *testing.T) {
s.st.skipped, len(s.batch))
}
warning := "hash " + p + ": not a regular file\n"
warning := "scan: skipped " + p + " (not a regular file)\n"
if got := stderr(); strings.Count(got, warning) != 1 {
t.Errorf("stderr = %q, want %q once", got, warning)
}