File tree Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ type CLI struct {
8080 Paths []string `arg:"" name:"paths" help:"directories to update"`
8181 SkipExisting bool `short:"s" help:"only add new and modified files, do not check existing (quicker)"`
8282 Force bool `help:"force update of damaged items (advanced usage only)"`
83+ KeepMissing bool `help:"keep missing files in the index"`
8384 } `cmd:"" help:"add and update modified files, also checking existing ones (see chkbit update -h)"`
8485
8586 Init struct {
@@ -327,6 +328,7 @@ func (m *Main) runCmd(command string, cli CLI) int {
327328 m .context .UpdateIndex = true
328329 m .context .UpdateSkipCheck = cli .Update .SkipExisting
329330 m .context .ForceUpdateDmg = cli .Update .Force
331+ m .context .KeepMissing = cli .Update .KeepMissing
330332 m .log ("chkbit update " + strings .Join (pathList , ", " ))
331333 case cmdShowIgnored :
332334 pathList = cli .ShowIgnored .Paths
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ type Context struct {
1515 UpdateIndex bool // add and update hashes
1616 UpdateSkipCheck bool // do not check existing hashes when updating
1717 ShowIgnoredOnly bool // print ignored files
18+ KeepMissing bool // keep missing files in index when updating
1819 LogDeleted bool // output deleted files and directories
1920 IncludeDot bool // include dot files
2021 ForceUpdateDmg bool
Original file line number Diff line number Diff line change @@ -169,9 +169,15 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
169169 // track deleted files
170170 for name := range i .cur {
171171 if _ , ok := i .new [name ]; ! ok {
172- i .modified = true
173- if i .context .LogDeleted {
174- i .logFile (StatusDeleted , name )
172+ // file missing
173+ if i .context .KeepMissing {
174+ // preserve old entry
175+ i .new [name ] = i .cur [name ]
176+ } else {
177+ i .modified = true
178+ if i .context .LogDeleted {
179+ i .logFile (StatusDeleted , name )
180+ }
175181 }
176182 }
177183 }
@@ -183,9 +189,15 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
183189 }
184190 for _ , name := range i .curDirList {
185191 if ! m [name ] {
186- i .modified = true
187- if i .context .LogDeleted {
188- i .logDir (StatusDeleted , name + "/" )
192+ // directory missing
193+ if i .context .KeepMissing {
194+ // preserve old directory
195+ i .newDirList = append (i .newDirList , name )
196+ } else {
197+ i .modified = true
198+ if i .context .LogDeleted {
199+ i .logDir (StatusDeleted , name + "/" )
200+ }
189201 }
190202 }
191203 }
You can’t perform that action at this time.
0 commit comments