Skip to content

Commit

Permalink
small changes as a result of logger changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmulvey committed Apr 10, 2024
1 parent af6de84 commit 22ec4ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 8 additions & 6 deletions cmd/nsquared/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {

flag.StringVar(&dir, "dir", "", "directory (abs path)")
flag.StringVar(&cacheFile, "cache-file", "cache.json", "json file to store the image hashes which be different for different input dirs")
flag.StringVar(&outputFile, "output-file", "delete.log", "log file to store the duplicate pairs")
flag.StringVar(&outputFile, "output-file", "delete.json", "json file to store the duplicate pairs, it will be deleted and recreated")
flag.IntVar(&threads, "threads", 1, "number of threads to use, >1 only useful when rebuilding the cache")
flag.IntVar(&depth, "depth", 2, "how far down the directory tree to search for files")
flag.IntVar(&distanceThreshold, "distance", 10, "max distance for images to be considered the same")
Expand All @@ -76,22 +76,23 @@ func main() {
}
os.Exit(0)
}
if strings.TrimSpace(dir) == "" {
log.Fatal("directory not provided")
if _, err := os.Stat(strings.TrimSpace(dir)); err != nil {
log.Fatalf("directory %s is not valid, err :%s \n", dir, err.Error())
}
if threads <= 0 || threads > runtime.GOMAXPROCS(0) {
threads = 1
}
if filepath.Ext(cacheFile) != ".json" {
log.Fatal("cache file must have extension .json")
}
if filepath.Ext(outputFile) != ".log" {
log.Fatal("output file must have extension .log")
if filepath.Ext(outputFile) != ".json" {
log.Fatal("output file must have extension .json")
}

// list all the files
var files, err = path.List(dir, uint8(depth), false, path.NewRegexEntitiesFilter(imagedup.ImageExtensionRegex))
handleErr("listFiles", err)

var fileNames = path.OnlyNames(files)
log.Infof("Found %d files", len(files))
if len(files) < 2 {
Expand All @@ -101,6 +102,7 @@ func main() {
// start er up
resultsLogger, err := logger.NewDeleteLogger(outputFile)
handleErr("NewImageDup", err)

id, err := imagedup.NewImageDup("imagedup", cacheFile, threads, len(files), distanceThreshold, dedupFilePairs)
handleErr("NewImageDup", err)

Expand Down Expand Up @@ -143,7 +145,7 @@ CollectionLoop:
if err != nil {
log.Fatal("error shutting down", err)
}

resultsLogger.Close()
log.Info("Total time taken: ", time.Since(start))
}

Expand Down
11 changes: 8 additions & 3 deletions cmd/uniqdirs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func main() {
}
os.Exit(0)
}
if strings.TrimSpace(rootDir) == "" {
log.Fatal("directory not provided")
if _, err := os.Stat(strings.TrimSpace(rootDir)); err != nil {
log.Fatalf("directory %s is not valid, err :%s \n", rootDir, err.Error())
}
if threads <= 0 || threads > runtime.GOMAXPROCS(0) {
threads = 1
Expand All @@ -83,6 +83,7 @@ func main() {
// list all the dirs
dirs, err := path.List(rootDir, uint8(depth), false, path.NewDirEntitiesFilter())
handleErr("listFiles", err)

var dirNames = path.OnlyNames(dirs)
log.Infof("Found %d dirs", len(dirNames))

Expand Down Expand Up @@ -116,19 +117,22 @@ func handleErr(prefix string, err error) {

// dedupDir returns a bool representing 'continue' which is usually true except when an os signal is received, then false
func dedupDir(ctx context.Context, cancel context.CancelFunc, dir string, threads, distanceThreshold, depth int, dedupFilePairs bool, gracefulShutdown chan os.Signal) bool {

// list all the files
var files, err = path.List(dir, uint8(depth), false, path.NewRegexEntitiesFilter(imagedup.ImageExtensionRegex))
handleErr("listFiles", err)

var fileNames = path.OnlyNames(files)
log.Infof("Found %d files", len(files))
if len(files) < 2 {
log.Infof("Skipping %s because there are only %d files", dir, len(files))
return true
}
// start er up

// start er up
resultsLogger, err := logger.NewDeleteLogger(filepath.Base(dir) + logExt)
handleErr("NewImageDup", err)

id, err := imagedup.NewImageDup("imagedup", filepath.Base(dir)+".json", threads, len(files), distanceThreshold, dedupFilePairs)
handleErr("NewImageDup", err)

Expand Down Expand Up @@ -167,6 +171,7 @@ func dedupDir(ctx context.Context, cancel context.CancelFunc, dir string, thread
if err != nil {
log.Fatal("error shutting down", err)
}
resultsLogger.Close()

return true
}
2 changes: 1 addition & 1 deletion cmd/verify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
var v bool
var help bool
flag.BoolVar(&alwaysDelete, "always-delete", false, "just take the larger one, always")
flag.Var(&deleteFiles, "delete-files", "log file where duplicate pairs are stored, same file from -cache-file when running nsquared")
flag.Var(&deleteFiles, "delete-files", "json file where duplicate pairs are stored, same file from -cache-file when running nsquared")
flag.BoolVar(&help, "help", false, "print help")
flag.BoolVar(&v, "version", false, "print version")
flag.BoolVar(&v, "v", false, "print version")
Expand Down

0 comments on commit 22ec4ee

Please sign in to comment.