Skip to content

Commit

Permalink
add option to include dot files, #21
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Oct 21, 2024
1 parent 03acfd8 commit d7c8cc4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmd/chkbit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Context struct {
AddOnly bool
ShowIgnoredOnly bool
ShowMissing bool
IncludeDot bool
ForceUpdateDmg bool
HashAlgo string
TrackDirectories bool
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 7 additions & 1 deletion ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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, "")
}

Expand Down
6 changes: 4 additions & 2 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 17 additions & 2 deletions scripts/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit d7c8cc4

Please sign in to comment.