Skip to content

Commit

Permalink
Allow to run check only, make datadir an optional parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <[email protected]>
  • Loading branch information
teran committed Nov 28, 2018
1 parent 18213c9 commit 98029e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
type config struct {
Concurrency int `names:"--concurrency, -c" usage:"Amount of routines to spawn at the same time for checksum verification"`
Complete bool `names:"--complete" usage:"Completion for shell"`
DataDir string `names:"--datadir, -d" usage:"Data directory path"`
DbPath string `names:"--database, -D" usage:"Database file path"`
DataDir string `names:"--datadir, -d" usage:"Data directory path to run new files scan"`
DbPath string `names:"--database, -D" usage:"Database file path (required)"`
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 All @@ -28,7 +28,7 @@ func newConfig() *config {
set := flag.NewFlagSet(flag.Flag{})
set.ParseStruct(&c, os.Args...)

if c.DataDir == "" || c.DbPath == "" {
if c.DbPath == "" {
set.Help(true)
os.Exit(1)
}
Expand Down
40 changes: 23 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,33 @@ func main() {
bar.Finish()
}

fmt.Printf("%s Verification step complete. Checking for new files on %s\n", color.CyanString("[INFO]"), cfg.DataDir)
fmt.Printf("%s Verification step complete\n", color.CyanString("[INFO]"))
}

err = filepath.Walk(cfg.DataDir, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
if cfg.DataDir != "" {
fmt.Printf("%s Checking for new files on %s", color.CyanString("[INFO]"), cfg.DataDir)

err = filepath.Walk(cfg.DataDir, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if isApplicable(path) {
db.WriteOne(path, database.Data{
Length: flength(path),
SHA1: sha1file(path),
SHA256: sha256file(path),
Modified: time.Now().UTC(),
})
fmt.Printf("%s %s\n", color.YellowString("[CALCULATED]"), path)
atomic.AddUint64(&cntAdded, 1)
}
return nil
})
if err != nil {
panic(fmt.Sprintf("Error walking through files: %s", err))
}
if isApplicable(path) {
db.WriteOne(path, database.Data{
Length: flength(path),
SHA1: sha1file(path),
SHA256: sha256file(path),
Modified: time.Now().UTC(),
})
fmt.Printf("%s %s\n", color.YellowString("[CALCULATED]"), path)
atomic.AddUint64(&cntAdded, 1)
}
return nil
})
if err != nil {
panic(fmt.Sprintf("Error walking through files: %s", err))
} else {
fmt.Printf("%s data directory is not specified. Skipping new files check\n", color.CyanString("[INFO]"))
}

err = db.Commit()
Expand Down

0 comments on commit 98029e9

Please sign in to comment.