Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/chkbit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type CLI struct {
Paths []string `arg:"" name:"paths" help:"directories to update"`
SkipExisting bool `short:"s" help:"only add new and modified files, do not check existing (quicker)"`
Force bool `help:"force update of damaged items (advanced usage only)"`
KeepMissing bool `help:"keep missing files in the index"`
} `cmd:"" help:"add and update modified files, also checking existing ones (see chkbit update -h)"`

Init struct {
Expand Down Expand Up @@ -327,6 +328,7 @@ func (m *Main) runCmd(command string, cli CLI) int {
m.context.UpdateIndex = true
m.context.UpdateSkipCheck = cli.Update.SkipExisting
m.context.ForceUpdateDmg = cli.Update.Force
m.context.KeepMissing = cli.Update.KeepMissing
m.log("chkbit update " + strings.Join(pathList, ", "))
case cmdShowIgnored:
pathList = cli.ShowIgnored.Paths
Expand Down
1 change: 1 addition & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Context struct {
UpdateIndex bool // add and update hashes
UpdateSkipCheck bool // do not check existing hashes when updating
ShowIgnoredOnly bool // print ignored files
KeepMissing bool // keep missing files in index when updating
LogDeleted bool // output deleted files and directories
IncludeDot bool // include dot files
ForceUpdateDmg bool
Expand Down
24 changes: 18 additions & 6 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,15 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
// track deleted files
for name := range i.cur {
if _, ok := i.new[name]; !ok {
i.modified = true
if i.context.LogDeleted {
i.logFile(StatusDeleted, name)
// file missing
if i.context.KeepMissing {
// preserve old entry
i.new[name] = i.cur[name]
} else {
i.modified = true
if i.context.LogDeleted {
i.logFile(StatusDeleted, name)
}
}
}
}
Expand All @@ -183,9 +189,15 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
}
for _, name := range i.curDirList {
if !m[name] {
i.modified = true
if i.context.LogDeleted {
i.logDir(StatusDeleted, name+"/")
// directory missing
if i.context.KeepMissing {
// preserve old directory
i.newDirList = append(i.newDirList, name)
} else {
i.modified = true
if i.context.LogDeleted {
i.logDir(StatusDeleted, name+"/")
}
}
}
}
Expand Down