From 806bb0f68e0e6157ad4c9d1ed58d1e51b12c06e1 Mon Sep 17 00:00:00 2001 From: Thushan Fernando Date: Sun, 12 Nov 2023 16:32:56 +1100 Subject: [PATCH 1/5] Ignore permission issues and read errors on Windows. --- pkg/indexer/indexer.go | 6 +++++- pkg/slicer/slicer.go | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/indexer/indexer.go b/pkg/indexer/indexer.go index 9dd0af7..a06b564 100644 --- a/pkg/indexer/indexer.go +++ b/pkg/indexer/indexer.go @@ -1,6 +1,7 @@ package indexer import ( + "errors" "io/fs" "path/filepath" "regexp" @@ -51,12 +52,15 @@ func NewConfigured(excludeDirFilter []string, excludeFileFilter []string) *Index func (config *IndexerConfig) WalkDirectory(f fs.FS, root string, files chan FileFS) error { walkErr := fs.WalkDir(f, ".", func(path string, d fs.DirEntry, err error) error { if err != nil { + if errors.Is(err, fs.ErrPermission) { + return fs.SkipDir + } return err } name := filepath.Clean(d.Name()) if d.IsDir() { if config.isSystemFolder(name) || (len(config.ExcludeDirFilter) > 0 && config.dirMatcher.MatchString(path)) { - return filepath.SkipDir + return fs.SkipDir } } else { if len(config.ExcludeFileFilter) > 0 && config.fileMatcher.MatchString(name) { diff --git a/pkg/slicer/slicer.go b/pkg/slicer/slicer.go index 3f4bbd6..ddb972f 100644 --- a/pkg/slicer/slicer.go +++ b/pkg/slicer/slicer.go @@ -3,10 +3,11 @@ package slicer import ( "encoding/gob" "errors" + "github.com/logrusorgru/aurora/v3" + "github.com/thushan/smash/internal/algorithms" "io" "io/fs" - - "github.com/thushan/smash/internal/algorithms" + "log" ) type Slicer struct { @@ -55,7 +56,15 @@ func (slicer *Slicer) SliceFS(fs fs.FS, name string, disableSlicing bool) (Slice stats := SlicerStats{Hash: slicer.defaultBytes, Filename: name} f, err := fs.Open(name) - defer f.Close() + defer func(fs io.Closer) { + if fs == nil { + // Ignore ReadOnly issues. + return + } + if err := fs.Close(); err != nil { + log.Println(aurora.Red("ERR"), aurora.Blue(name), err) + } + }(f) if err != nil { return stats, err From 42a073add3a65316188875651d39bb5b6f9ead6e Mon Sep 17 00:00:00 2001 From: Thushan Fernando Date: Sun, 12 Nov 2023 16:33:30 +1100 Subject: [PATCH 2/5] Clearer separation of areas. --- internal/smash/configuration.go | 2 +- internal/smash/formatter.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/smash/configuration.go b/internal/smash/configuration.go index 60ffe3b..5447204 100644 --- a/internal/smash/configuration.go +++ b/internal/smash/configuration.go @@ -12,7 +12,7 @@ import ( func (app *App) printConfiguration() { f := app.Flags - log.Println(Bold(Cyan("Configuration"))) + log.Println(Bold(Cyan("---| Configuration"))) log.Println(Bold("Locations: "), Magenta(strings.Join(app.Locations, ", "))) log.Println(Bold("Algorithm: "), Magenta(algorithms.Algorithm(f.Algorithm))) log.Println(Bold("Max Workers: "), Magenta(f.MaxWorkers)) diff --git a/internal/smash/formatter.go b/internal/smash/formatter.go index 7bb85a8..d1546dd 100644 --- a/internal/smash/formatter.go +++ b/internal/smash/formatter.go @@ -22,6 +22,7 @@ func (app *App) printVerbose(message ...any) { func (app *App) printSmashHits(cache *haxmap.Map[string, []SmashFile]) uint64 { totalDuplicateSize := uint64(0) + log.Println(aurora.Cyan(aurora.Bold("---| Duplicates"))) cache.ForEach(func(hash string, files []SmashFile) bool { mainFile := files[0] lastIndex := len(files) @@ -47,8 +48,13 @@ func (app *App) printSmashHits(cache *haxmap.Map[string, []SmashFile]) uint64 { } func (app *App) printSmashRunSummary(rs RunSummary) { + log.Println(aurora.Cyan(aurora.Bold("---| Summary"))) log.Println("Total Time: ", aurora.Green(fmt.Sprintf("%dms", rs.ElapsedTime))) log.Println("Total Files: ", aurora.Blue(rs.TotalFiles)) log.Println("Total Unique: ", aurora.Blue(rs.UniqueFiles)) - log.Println("Total Duplicates: ", aurora.Blue(rs.DuplicateFiles), "(", aurora.Cyan(rs.DuplicateFileSizeF), " can be reclaimed).") + log.Println("Total Duplicates: ", aurora.Blue(rs.DuplicateFiles)) + if rs.DuplicateFileSize > 0 { + log.Println("Total Reclaimable: ", aurora.Cyan(rs.DuplicateFileSizeF)) + } + } From f7ee201693a595d843124bcb8ec2a61e2bc30adb Mon Sep 17 00:00:00 2001 From: Thushan Fernando Date: Sun, 12 Nov 2023 16:56:21 +1100 Subject: [PATCH 3/5] Bump version --- internal/smash/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/smash/version.go b/internal/smash/version.go index c8ad0f2..99c8241 100644 --- a/internal/smash/version.go +++ b/internal/smash/version.go @@ -7,7 +7,7 @@ import ( ) var ( - Version string = "v0.0.1" + Version string = "v0.0.2" Commit string = "none" Date string = "unknown" Home string = "github.com/thushan/smash" From 196a7506fa92de1e0d2ebedf8f65302e9337fe78 Mon Sep 17 00:00:00 2001 From: Thushan Fernando Date: Sun, 12 Nov 2023 17:14:40 +1100 Subject: [PATCH 4/5] Message for no duplicates. --- internal/smash/formatter.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/smash/formatter.go b/internal/smash/formatter.go index d1546dd..869327e 100644 --- a/internal/smash/formatter.go +++ b/internal/smash/formatter.go @@ -44,6 +44,9 @@ func (app *App) printSmashHits(cache *haxmap.Map[string, []SmashFile]) uint64 { } return true }) + if cache.Len() == 0 { + log.Println(aurora.Green("No duplicates found :-)")) + } return totalDuplicateSize } From c1451ee9f2e34363ccdbcb340c3e034d1ae81c0c Mon Sep 17 00:00:00 2001 From: Thushan Fernando Date: Sun, 12 Nov 2023 17:23:38 +1100 Subject: [PATCH 5/5] lint fix. --- pkg/slicer/slicer.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/slicer/slicer.go b/pkg/slicer/slicer.go index ddb972f..d3dce17 100644 --- a/pkg/slicer/slicer.go +++ b/pkg/slicer/slicer.go @@ -3,11 +3,12 @@ package slicer import ( "encoding/gob" "errors" - "github.com/logrusorgru/aurora/v3" - "github.com/thushan/smash/internal/algorithms" "io" "io/fs" "log" + + "github.com/logrusorgru/aurora/v3" + "github.com/thushan/smash/internal/algorithms" ) type Slicer struct { @@ -61,8 +62,8 @@ func (slicer *Slicer) SliceFS(fs fs.FS, name string, disableSlicing bool) (Slice // Ignore ReadOnly issues. return } - if err := fs.Close(); err != nil { - log.Println(aurora.Red("ERR"), aurora.Blue(name), err) + if ferr := fs.Close(); ferr != nil { + log.Println(aurora.Red("ERR"), aurora.Blue(name), ferr) } }(f)