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

Implement minSize/maxSize thresholds. #58

Merged
merged 7 commits into from
Feb 4, 2024
Merged
Changes from 1 commit
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
Next Next commit
initial minsize maxsize
thushan committed Feb 3, 2024

Verified

This commit was signed with the committer’s verified signature.
thushan Thushan Fernando
commit b37196360de742f835d04d2ff988d296588b891a
3 changes: 3 additions & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ func init() {
flags.StringSliceVarP(&af.ExcludeDir, "exclude-dir", "", nil, "Directories to exclude separated by comma Eg. --exclude-dir=.git,.idea")
flags.IntVarP(&af.MaxThreads, "max-threads", "p", runtime.NumCPU(), "Maximum threads to utilise")
flags.IntVarP(&af.MaxWorkers, "max-workers", "w", runtime.NumCPU(), "Maximum workers to utilise when smashing")
flags.Uint64VarP(&af.MinSize, "min-size", "G", 0, "Minimum file size to consider for hashing (in bytes)")
flags.Uint64VarP(&af.MaxSize, "max-size", "L", 0, "Maximum file size to consider for hashing (in bytes)")
flags.IntVarP(&af.ProgressUpdate, "progress-update", "", 5, "Update progress every x seconds")
flags.IntVarP(&af.ShowTop, "show-top", "", 10, "Show the top x duplicates")
flags.BoolVarP(&af.HideTopList, "no-top-list", "", false, "Hides top x duplicates list")
@@ -49,6 +51,7 @@ func init() {
flags.BoolVarP(&af.IgnoreEmpty, "ignore-empty", "", true, "Ignore empty/zero byte files")
flags.BoolVarP(&af.IgnoreHidden, "ignore-hidden", "", true, "Ignore hidden files & folders Eg. files/folders starting with '.'")
flags.BoolVarP(&af.IgnoreSystem, "ignore-system", "", true, "Ignore system files & folders Eg. '$MFT', '.Trash'")

flags.BoolVarP(&af.Silent, "silent", "q", false, "Run in silent mode")
flags.BoolVarP(&af.Recurse, "recurse", "r", false, "Recursively search directories for files")
flags.BoolVarP(&af.Verbose, "verbose", "", false, "Run in verbose mode")
2 changes: 2 additions & 0 deletions internal/smash/app.go
Original file line number Diff line number Diff line change
@@ -161,6 +161,8 @@ func (app *App) Exec() error {
theme.WarnSkipWithContext(file.FullName, err)
}
_, _ = session.Fails.LoadOrStore(file.Path, err)
} else if stats.IgnoredFile {
//
} else {
SummariseSmashedFile(stats, file, elapsedMs, session.Dupes, session.Empty)
}
2 changes: 2 additions & 0 deletions internal/smash/flags.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ type Flags struct {
Base []string `yaml:"base"`
ExcludeDir []string `yaml:"exclude-dir"`
ExcludeFile []string `yaml:"exclude-file"`
MinSize uint64 `yaml:"min-size"`
MaxSize uint64 `yaml:"max-size"`
Algorithm int `yaml:"algorithm"`
MaxThreads int `yaml:"max-threads"`
MaxWorkers int `yaml:"max-workers"`
29 changes: 22 additions & 7 deletions pkg/slicer/slicer.go
Original file line number Diff line number Diff line change
@@ -27,14 +27,17 @@ type SlicerStats struct {
SliceSize uint64
FileSize uint64
Slices int
HashedFullFile bool
EmptyFile bool
IgnoredFile bool
HashedFullFile bool
}

type MetaSlice struct {
Size uint64
}
type Options struct {
MinSize uint64
MaxSize uint64
DisableSlicing bool
DisableMeta bool
DisableAutoText bool
@@ -84,20 +87,26 @@ func (slicer *Slicer) SliceFS(fs fs.FS, name string, options *Options) (SlicerSt
return stats, err
}

size := fi.Size()

stats.FileSize = uint64(size)
stats.Slices = slicer.slices
stats.SliceSize = slicer.sliceSize
size := uint64(fi.Size())

if size == 0 {
stats.EmptyFile = true
stats.Hash = nil
return stats, nil
}

if (options.MinSize > 0 && size < options.MinSize) ||
(options.MaxSize > 0 && size > options.MaxSize) {
stats.IgnoredFile = true
return stats, nil
}

stats.FileSize = size
stats.Slices = slicer.slices
stats.SliceSize = slicer.sliceSize

if fr, ok := f.(io.ReaderAt); ok {
sr := io.NewSectionReader(fr, 0, size)
sr := io.NewSectionReader(fr, 0, int64(size))
err := slicer.Slice(sr, options, &stats)
return stats, err
} else {
@@ -141,6 +150,12 @@ func (slicer *Slicer) Slice(sr *io.SectionReader, options *Options, stats *Slice
return nil
}

if (options.MinSize > 0 && size < options.MinSize) ||
(options.MaxSize > 0 && size > options.MaxSize) {
stats.IgnoredFile = true
return nil
}

algo := slicer.algorithm.New()
algo.Reset()