Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Windows compatibility issues with Junctions #16

Merged
merged 5 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/smash/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 10 additions & 1 deletion internal/smash/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -43,12 +44,20 @@ 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
}

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))
}

}
2 changes: 1 addition & 1 deletion internal/smash/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion pkg/indexer/indexer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indexer

import (
"errors"
"io/fs"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion pkg/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"errors"
"io"
"io/fs"
"log"

"github.com/logrusorgru/aurora/v3"
"github.com/thushan/smash/internal/algorithms"
)

Expand Down Expand Up @@ -55,7 +57,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 ferr := fs.Close(); ferr != nil {
log.Println(aurora.Red("ERR"), aurora.Blue(name), ferr)
}
}(f)

if err != nil {
return stats, err
Expand Down
Loading