diff --git a/cmd/chkbit/main.go b/cmd/chkbit/main.go index ee5ec4d..d163691 100644 --- a/cmd/chkbit/main.go +++ b/cmd/chkbit/main.go @@ -49,6 +49,7 @@ var cli struct { AddOnly bool `short:"a" help:"add mode: only add new files, do not check existing (quicker)"` ShowIgnoredOnly bool `short:"i" help:"show-ignored mode: only show ignored files"` ShowMissing bool `short:"m" help:"show missing files/directories"` + IncludeDot bool `short:"d" help:"include dot files"` Force bool `help:"force update of damaged items (advanced usage only)"` SkipSymlinks bool `short:"S" help:"do not follow symlinks"` NoRecurse bool `short:"R" help:"do not recurse into subdirectories"` @@ -175,6 +176,7 @@ func (m *Main) process() bool { m.context.AddOnly = cli.AddOnly m.context.ShowIgnoredOnly = cli.ShowIgnoredOnly m.context.ShowMissing = cli.ShowMissing + m.context.IncludeDot = cli.IncludeDot m.context.SkipSymlinks = cli.SkipSymlinks m.context.SkipSubdirectories = cli.NoRecurse m.context.TrackDirectories = !cli.NoDirInIndex diff --git a/context.go b/context.go index b94ca08..9a36c5a 100644 --- a/context.go +++ b/context.go @@ -13,6 +13,7 @@ type Context struct { AddOnly bool ShowIgnoredOnly bool ShowMissing bool + IncludeDot bool ForceUpdateDmg bool HashAlgo string TrackDirectories bool @@ -168,12 +169,6 @@ func (context *Context) scanDir(root string, parentIgnore *Ignore) { for _, file := range files { path := filepath.Join(root, file.Name()) - if file.Name()[0] == '.' { - if context.ShowIgnoredOnly && !context.isChkbitFile(file.Name()) { - context.log(STATUS_IGNORE, path) - } - continue - } if isDir(file, path) { if !ignore.shouldIgnore(file.Name()) { dirList = append(dirList, file.Name()) diff --git a/ignore.go b/ignore.go index b60b497..560e760 100644 --- a/ignore.go +++ b/ignore.go @@ -24,7 +24,7 @@ func GetIgnore(context *Context, path string, parentIgnore *Ignore) (*Ignore, er } err := ignore.loadIgnore() if err != nil { - return nil, err + return ignore, err } return ignore, nil } @@ -58,6 +58,12 @@ func (ignore *Ignore) loadIgnore() error { } func (ignore *Ignore) shouldIgnore(name string) bool { + if ignore.context.isChkbitFile(name) { + return true + } + if !ignore.context.IncludeDot && name[0] == '.' { + return true + } return ignore.shouldIgnore2(name, "") } diff --git a/index.go b/index.go index 694d2d9..4051035 100644 --- a/index.go +++ b/index.go @@ -82,8 +82,10 @@ func (i *Index) logDir(stat Status, name string) { func (i *Index) calcHashes(ignore *Ignore) { for _, name := range i.files { - if ignore != nil && ignore.shouldIgnore(name) { - i.logFile(STATUS_IGNORE, name) + if ignore.shouldIgnore(name) { + if !ignore.context.isChkbitFile(name) { + i.logFile(STATUS_IGNORE, name) + } continue } diff --git a/scripts/run_test.go b/scripts/run_test.go index eb049ad..f27e59a 100644 --- a/scripts/run_test.go +++ b/scripts/run_test.go @@ -261,8 +261,8 @@ func TestRoot(t *testing.T) { checkOut(t, sout, "- 1 file hash was updated") }) - // ignore hidden - t.Run("ignore-hidden", func(t *testing.T) { + // ignore dot + t.Run("ignore-dot", func(t *testing.T) { genFiles(filepath.Join(root, "way/.hidden"), 99) genFile(filepath.Join(root, "time/.ignored"), 999) @@ -275,6 +275,21 @@ func TestRoot(t *testing.T) { sout := string(out) checkOut(t, sout, "Processed 295 files") }) + + // include dot + t.Run("include-dot", func(t *testing.T) { + + cmd := exec.Command(tool, "-u", "-d", root) + out, err := cmd.Output() + if err != nil { + t.Fatalf("failed with '%s'\n", err) + } + sout := string(out) + checkOut(t, sout, "Processed 301 files") + checkOut(t, sout, "- 3 directories were updated") + checkOut(t, sout, "- 6 file hashes were added") + checkOut(t, sout, "- 0 file hashes were updated") + }) } func TestDMG(t *testing.T) {