From b6c8960b01f9e5366814b0dada57a0b1e6a031d9 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 2 Apr 2018 18:32:30 +0200 Subject: fsck: clean up log output Make sure we get only 1 warning output per problem. Also, add new corruption types to broken_fs_v1.4. --- fsck.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'fsck.go') diff --git a/fsck.go b/fsck.go index 32788e5..1954fa5 100644 --- a/fsck.go +++ b/fsck.go @@ -16,8 +16,13 @@ import ( ) type fsckObj struct { - fs *fusefrontend.FS - errorCount int + fs *fusefrontend.FS + // List of corrupt files + corruptList []string +} + +func (ck *fsckObj) markCorrupt(path string) { + ck.corruptList = append(ck.corruptList, path) } // Recursively check dir for corruption @@ -25,8 +30,8 @@ func (ck *fsckObj) dir(path string) { //fmt.Printf("ck.dir %q\n", path) entries, status := ck.fs.OpenDir(path, nil) if !status.Ok() { + ck.markCorrupt(path) fmt.Printf("fsck: error opening dir %q: %v\n", path, status) - ck.errorCount++ return } // Sort alphabetically @@ -56,8 +61,8 @@ func (ck *fsckObj) dir(path string) { func (ck *fsckObj) symlink(path string) { _, status := ck.fs.Readlink(path, nil) if !status.Ok() { + ck.markCorrupt(path) fmt.Printf("fsck: error reading symlink %q: %v\n", path, status) - ck.errorCount++ } } @@ -66,8 +71,8 @@ func (ck *fsckObj) file(path string) { //fmt.Printf("ck.file %q\n", path) f, status := ck.fs.Open(path, syscall.O_RDONLY, nil) if !status.Ok() { + ck.markCorrupt(path) fmt.Printf("fsck: error opening file %q: %v\n", path, status) - ck.errorCount++ return } defer f.Release() @@ -76,8 +81,8 @@ func (ck *fsckObj) file(path string) { for { result, status := f.Read(buf, off) if !status.Ok() { + ck.markCorrupt(path) fmt.Printf("fsck: error reading file %q at offset %d: %v\n", path, off, status) - ck.errorCount++ return } // EOF @@ -95,16 +100,21 @@ func fsck(args *argContainer) { } args.allow_other = false pfs, wipeKeys := initFuseFrontend(args) - defer wipeKeys() fs := pfs.(*fusefrontend.FS) ck := fsckObj{ fs: fs, } ck.dir("") - fmt.Printf("fsck: found %d problems\n", ck.errorCount) - if ck.errorCount != 0 { - os.Exit(exitcodes.FsckErrors) + wipeKeys() + if len(ck.corruptList) == 0 { + fmt.Printf("fsck summary: no problems found") + return + } + fmt.Printf("fsck summary: found %d corrupt files:\n", len(ck.corruptList)) + for _, path := range ck.corruptList { + fmt.Printf(" %q\n", path) } + os.Exit(exitcodes.FsckErrors) } type sortableDirEntries []fuse.DirEntry -- cgit v1.2.3