muka

package
v0.0.0-...-9b04029 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileSpaceSeparatedPatterns

func CompileSpaceSeparatedPatterns(s string) ([]*regexp.Regexp, error)

CompileSpaceSeparatedPatterns takes a string of space separated regexes and compiles them into regex state machines. If the input is empty, an empty array is returned with no errors If any error occurs while compiling one of the patterns, that error is returned along with whatever patterns where previously compiled.

func PrintDuplicates

func PrintDuplicates(duplicates []DuplicateFile)

PrintDuplicates print the duplicate to stdout

Types

type Deleter

type Deleter interface {
	Delete(path string) error
}

Deleter delete function interface

func MakeDeleter

func MakeDeleter(isDryRun bool) Deleter

MakeDeleter a Deleter factory function

type Directory

type Directory struct {
	EncounteredFiles []FileData
	HashedFiles      []FileHash
}

Directory holds the collected information about a directory

func CollectFiles

func CollectFiles(options FileCollectionOptions) (Directory, error)

CollectFiles Recursively walks the provided directory and processes each file and directory it encounters This function will return, in order, a list of all the files it encountered, a list of files that were hashed, and an error if one is encountered.

type DuplicateFile

type DuplicateFile struct {
	Original   FileHash
	Duplicates []FileHash
}

DuplicateFile holds original and duplicate FileHashes

func FindDuplicateFiles

func FindDuplicateFiles(directory Directory) []DuplicateFile

FindDuplicateFiles does as it suggests

func (DuplicateFile) String

func (duplicate DuplicateFile) String() string

type DuplicateFileCache

type DuplicateFileCache struct {
	// contains filtered or unexported fields
}

DuplicateFileCache holds a cache of possible duplicate muka

func NewCache

func NewCache() DuplicateFileCache

NewCache duplicateFileCache constructor

func (*DuplicateFileCache) Add

func (cache *DuplicateFileCache) Add(hash FileHash)

Add adds a FileHash to the cache accounting for possible duplicates

func (*DuplicateFileCache) GetDuplicates

func (cache *DuplicateFileCache) GetDuplicates() []DuplicateFile

GetDuplicates retrieves the list of duplicates from the cache

type FileCollectionOptions

type FileCollectionOptions struct {
	DirectoryToSearch string
	ExcludeDirs       []*regexp.Regexp
	ExcludeFiles      []*regexp.Regexp
}

FileCollectionOptions options used by CollectFiles

type FileData

type FileData struct {
	AbsolutePath string
	SizeInBytes  int64
}

FileData holds basic metadata about a file

type FileHash

type FileHash struct {
	FileData
	Hash string
}

FileHash defines the file hash

func ForceDelete

func ForceDelete(duplicates []DuplicateFile, deleter Deleter) []FileHash

ForceDelete deletes the duplicates without asking for user interventionand returns all of the deleted files

func PromptToDelete

func PromptToDelete(writer io.Writer, reader io.Reader, deleter Deleter, dup DuplicateFile) ([]FileHash, error)

PromptToDelete this function interactively prompts the user to delete the duplicate and returns any files the user has deleted

func (FileHash) String

func (hash FileHash) String() string

type FileSizeCache

type FileSizeCache map[int64]int

FileSizeCache is a mapping between the size of a file and the count

type Report

type Report struct {
	CollectedFileCount    int
	CollectedFileSizeInKB float64
	DuplicateFileCount    int
	DuplicateFileSizeInKB float64
	DuplicatePercentage   float64
	DeletedFileCount      int
	DeletedFileSizeInKB   float64
}

Report reports on program performance

func CalculateReport

func CalculateReport(directory Directory, duplicates []DuplicateFile, deletedFiles []FileHash) Report

CalculateReport Generates a report detailing basic program behavior

func (Report) String

func (r Report) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL