diff --git a/config.go b/config.go index 0cec6f0..179bed2 100644 --- a/config.go +++ b/config.go @@ -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"` @@ -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. ` ) diff --git a/database/database.go b/database/database.go index 30104d3..27c7dcc 100644 --- a/database/database.go +++ b/database/database.go @@ -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() diff --git a/main.go b/main.go index b0c15aa..11e4215 100644 --- a/main.go +++ b/main.go @@ -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 }