core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAction

func ApplyAction(action Action, keep models.FileInfo, dup models.FileInfo, backupDir string) error

ApplyAction performs the given action on a duplicate file.

func ApplyKeepStrategy

func ApplyKeepStrategy(group models.DuplicateGroup, strategy string) (keep models.FileInfo, toRemove []models.FileInfo)

ApplyKeepStrategy selects which file to keep and which to remove.

func BuildReport

func BuildReport(allFiles []models.FileInfo, groups []models.DuplicateGroup, scanPath string) models.Report

BuildReport creates a Report from the scan results.

func CountHardLinks(files []models.FileInfo) int

CountHardLinks returns the number of files that are already hard-linked.

func DeleteFile

func DeleteFile(path string) error

DeleteFile removes a single file.

func ExportCSV

func ExportCSV(report models.Report, path string) error

ExportCSV writes a Report to a CSV file, one row per file.

func ExportHTML

func ExportHTML(report models.Report, path string) error

ExportHTML writes a Report to a styled HTML file.

func ExportJSON

func ExportJSON(report models.Report, path string) error

ExportJSON writes a Report to a JSON file.

func FindDuplicates

func FindDuplicates(files []models.FileInfo, workers int) []models.DuplicateGroup

FindDuplicates runs the full two-stage dedup pipeline: size grouping → Blake3 → SHA256 verification → duplicate groups.

func FormatSize

func FormatSize(bytes int64) string

FormatSize returns a human-readable file size string.

func GroupByHash

func GroupByHash(annotated []AnnotatedFile) map[string][]models.FileInfo

GroupByHash groups annotated files by their hash, returning only groups with 2+ files.

func GroupBySize

func GroupBySize(files []models.FileInfo) map[int64][]models.FileInfo

GroupBySize groups files by their size, returning only groups with 2+ files.

func HashBlake3

func HashBlake3(path string) (string, error)

HashBlake3 computes the Blake3 hash of a file.

func HashSHA256

func HashSHA256(path string) (string, error)

HashSHA256 computes the SHA256 hash of a file.

func ImportJSON

func ImportJSON(path string) (models.Report, error)

ImportJSON reads a Report from a JSON file.

func MoveToBackup

func MoveToBackup(dup, backupDir string) error

MoveToBackup moves a duplicate file to a backup directory, preserving structure.

func PlatformName

func PlatformName() string

PlatformName returns a human-readable name for the current OS/arch.

func ReplaceWithHardLink(keep, dup string) error

ReplaceWithHardLink replaces dup with a hard link to keep.

func ReplaceWithSoftLink(keep, dup string) error

ReplaceWithSoftLink replaces dup with a symbolic link to keep.

func Scan

func Scan(cfg ScanConfig) ([]models.FileInfo, error)

Scan discovers files using filepath.WalkDir for better performance, applies filters, and returns a list of FileInfo.

func SortGroupsByCount

func SortGroupsByCount(groups []models.DuplicateGroup)

SortGroupsByCount sorts groups by number of copies descending.

func SortGroupsByPath

func SortGroupsByPath(groups []models.DuplicateGroup)

SortGroupsByPath sorts groups alphabetically by first file path.

func SortGroupsBySize

func SortGroupsBySize(groups []models.DuplicateGroup)

SortGroupsBySize sorts groups by file size descending (default).

Types

type Action

type Action int

Action represents a file operation to perform.

const (
	ActionNone Action = iota
	ActionDelete
	ActionHardLink
	ActionSoftLink
	ActionBackup
)

type AnnotatedFile

type AnnotatedFile struct {
	File models.FileInfo
	Hash string
}

AnnotatedFile pairs a models.FileInfo with a hash result.

func AnnotateFiles

func AnnotateFiles(files []models.FileInfo, algorithm string, workers int) []AnnotatedFile

AnnotateFiles adds hashes to file infos concurrently.

type HashResult

type HashResult struct {
	Path string
	Hash string
	Err  error
}

HashResult is a single file hash result.

func HashPipeline

func HashPipeline(paths []string, algorithm string, workers int) []HashResult

HashPipeline hashes a list of files concurrently using the given algorithm. algorithm: "blake3" or "sha256"

type ScanConfig

type ScanConfig struct {
	Path         string
	Recursive    bool
	MinSize      int64
	MaxSize      int64
	Exclude      []string
	ExcludeRegex []string
	ExcludeDir   []string
	Workers      int
	OnProgress   func(stats models.ScanStats)
}

ScanConfig holds options for the file scanner.

Jump to

Keyboard shortcuts

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