diff options
| author | Jakob Unterwurzacher | 2026-11-19 20:48:14 +0100 |
|---|---|---|
| committer | Jakob Unterwurzacher | 2026-11-19 20:48:14 +0100 |
| commit | 4673301f2f1a08b3179b482deaa50f2a2a464753 (patch) | |
| tree | 1f9a49ddfbe93fb73433dff75348579d01b1207b /fsck.go | |
| parent | c4ef68bbbd182901d861d3f9c413d9c8a509b926 (diff) | |
fsck: count permission errors as skipped, not corrupt
The err == os.ErrPermission comparisons never matched, because os.Open
returns a *PathError. Permission errors on dirs and files were hence
counted as corrupt even when not running as root. The xattr check
compared against syscall.EACCES only and missed EPERM.
Add markError(), which uses errors.Is(err, os.ErrPermission) and so
handles both EACCES and EPERM, also when wrapped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'fsck.go')
| -rw-r--r-- | fsck.go | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "io" "os" @@ -53,6 +54,16 @@ func (ck *fsckObj) markSkipped(path string) { ck.listLock.Unlock() } +// markError marks relPath as skipped if err is a permission error and we +// are not root, and as corrupt otherwise. +func (ck *fsckObj) markError(relPath string, err error) { + if errors.Is(err, os.ErrPermission) && !runsAsRoot() { + ck.markSkipped(relPath) + } else { + ck.markCorrupt(relPath) + } +} + func (ck *fsckObj) abs(relPath string) (absPath string) { return filepath.Join(ck.mnt, relPath) } @@ -80,11 +91,7 @@ func (ck *fsckObj) dir(relPath string) { ck.watchDone <- struct{}{} if err != nil { fmt.Printf("fsck: error opening dir %q: %v\n", relPath, err) - if err == os.ErrPermission && !runsAsRoot() { - ck.markSkipped(relPath) - } else { - ck.markCorrupt(relPath) - } + ck.markError(relPath, err) return } go ck.watchMitigatedCorruptionsOpenDir(relPath) @@ -171,11 +178,7 @@ func (ck *fsckObj) file(relPath string) { f, err := os.Open(ck.abs(relPath)) if err != nil { fmt.Printf("fsck: error opening file %q: %v\n", relPath, err) - if err == os.ErrPermission && !runsAsRoot() { - ck.markSkipped(relPath) - } else { - ck.markCorrupt(relPath) - } + ck.markError(relPath, err) return } defer f.Close() @@ -245,11 +248,7 @@ func (ck *fsckObj) xattrs(relPath string) { _, err := syscallcompat.Lgetxattr(ck.abs(relPath), a) if err != nil { fmt.Printf("fsck: error reading xattr %q from %q: %v\n", a, relPath, err) - if err == syscall.EACCES && !runsAsRoot() { - ck.markSkipped(relPath) - } else { - ck.markCorrupt(relPath) - } + ck.markError(relPath, err) } } } |
