Skip to content

Commit

Permalink
Add flag to delete missed files from database
Browse files Browse the repository at this point in the history
Useful for moved files and similar cases.

Signed-off-by: Igor Shishkin <[email protected]>
  • Loading branch information
teran committed May 14, 2019
1 parent 22acaaa commit d069d42
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type config struct {
Complete bool `names:"--complete" usage:"Completion for shell"`
DataDir string `names:"--datadir, -d" usage:"Data directory path to run new files scan"`
DbPath string `names:"--database, -D" usage:"Database file path (required)"`
DeleteMissed bool `names:"--delete-missed" usage:"Delete missed files from database"`
GenerateChecksumOnly bool `names:"--generate-checksums-only" usage:"Skip verification step and add new files only"`
Pattern string `names:"--pattern, -p" usage:"Pattern to match filenames which checking for new files"`
SkipFailed bool `names:"--skip-failed, --sf" usage:"Skip FAIL verification results from output"`
Expand Down Expand Up @@ -60,7 +61,7 @@ func (c *config) Metadata() map[string]flag.Flag {
`, version, commit, runtime.Version(), date)

desc = `
checksum creates database (actually just a JSON file) to store file length, SHA1, SHA256
checksum creates database (actually just a JSON file) to store file length, SHA1, SHA256
to verify file consistency and report if something goes wrong.
`
)
Expand Down
13 changes: 13 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ func (d *Database) WriteOne(path string, data Data) (Data, bool) {
return data, ok
}

// DeleteOne deletes Data entry for specified path
func (d *Database) DeleteOne(path string) bool {
mutex.Lock()
defer mutex.Unlock()

if _, ok := d.Schema.Data[path]; !ok {
return false
}

delete(d.Schema.Data, path)
return true
}

// Count returns count of elements in database
func (d *Database) Count() int {
mutex.Lock()
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func main() {
if !cfg.SkipMissed {
fmt.Printf("%s %s\n", color.RedString("[MISS]"), file)
}

if cfg.DeleteMissed {
fmt.Printf("%s DeleteMissed requested: deleting file `%s` from database\n", color.BlueString("[NOTE]"), file)
db.DeleteOne(file)
}

atomic.AddUint64(&cntMissed, 1)
return
}
Expand Down

0 comments on commit d069d42

Please sign in to comment.