index

package
v0.0.0-...-1801604 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Digest

type Digest [32]byte

Digest is the output of the hash function.

type Dup

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

Dup is a directory that can be deleted without losing too much data.

func (*Dup) Alts

func (u *Dup) Alts() []string

Alts returns alternate directories that contain duplicate content.

func (*Dup) FileMap

func (u *Dup) FileMap(alt string) map[*File]*File

FileMap returns a map of files in u that have copies outside u. If alt is specified, only files that have copies in alt are returned.

func (*Dup) Ignored

func (u *Dup) Ignored() Files

Ignored returns empty and other ignored files that may be lost if d is deleted.

func (*Dup) Lost

func (u *Dup) Lost() Files

Lost returns unique files that would be lost if d is deleted.

type File

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

File is a regular file in the file system.

func (*File) Digest

func (f *File) Digest() Digest

Digest returns file digest.

func (*File) Flag

func (f *File) Flag() Flag

Flag returns file flags.

func (*File) ModTime

func (f *File) ModTime() time.Time

ModTime returns file modification time.

func (*File) Size

func (f *File) Size() int64

Size returns file size.

func (File) String

func (p File) String() string

String returns the path as a string.

type Files

type Files []*File

Files is an ordered list of files.

func (Files) Sort

func (fs Files) Sort()

Sort sorts files by path and other attributes.

type Flag

type Flag byte

Flag specifies file flags.

func (Flag) IsDup

func (a Flag) IsDup() bool

IsDup returns whether this file is a duplicate that may be removed.

func (Flag) IsGone

func (a Flag) IsGone() bool

IsGone returns whether the file no longer exists.

func (Flag) IsJunk

func (a Flag) IsJunk() bool

IsJunk returns whether the file and all of its copies may be removed.

func (Flag) IsSafe

func (a Flag) IsSafe() bool

IsSafe returns whether the file exists and is not marked for removal.

func (Flag) Keep

func (a Flag) Keep() bool

Keep returns whether the file must be preserved.

func (Flag) MayRemove

func (a Flag) MayRemove() bool

MayRemove returns whether the file may be removed.

func (Flag) String

func (a Flag) String() string

String returns the string representation of file flags.

type Hasher

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

Hasher is a file hasher.

func NewHasher

func NewHasher(monitor func(n int) error) *Hasher

NewHasher returns a new file hasher. If monitor is non-nil, it is called after every write with the number of bytes written. Hashing is aborted if monitor returns an error.

func (*Hasher) Read

func (h *Hasher) Read(fsys fs.FS, name string, nameFallback bool) (*File, error)

Read computes the digest of the specified file. If the file is empty and nameFallback is true, it computes the digest of name. If fsys is nil, it is set to the parent directory using os.DirFS.

type Index

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

Index is the root of an indexed file system.

func Load

func Load(name string) (*Index, error)

Load loads index contents from the specified file path.

func New

func New(root string, all Files) *Index

New creates a new file index.

func Read

func Read(src io.Reader) (*Index, error)

Read reads index contents from src.

func Scan

func Scan(ctx context.Context, fsys fs.FS, errFn func(error), progFn func(*Progress)) (*Index, error)

Scan creates an index of fsys. If errFn is non-nil, it is called for any file-specific errors. If progFn is non-nil, it is called at regular intervals to report progress. A non-nil error is returned if ctx is canceled.

func (*Index) Files

func (x *Index) Files() Files

Files returns all files.

func (*Index) Overwrite

func (x *Index) Overwrite(name string) error

Overwrite saves index contents to the specified file path. If the file already exists, it is overwritten.

func (*Index) Root

func (x *Index) Root() string

Root returns the index root directory.

func (*Index) Save

func (x *Index) Save(name string) error

Save saves index contents to the specified file path. If the file already exists, it is first renamed with a ".bak" extension.

func (*Index) ToTree

func (x *Index) ToTree() *Tree

ToTree converts from an index to a tree representation.

func (*Index) Write

func (x *Index) Write(dst io.Writer) error

Write writes index contents to dst.

type Progress

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

Progress reports file indexing progress.

func (*Progress) Duration

func (p *Progress) Duration() time.Duration

Duration returns the duration of the operation rounded to the nearest second.

func (*Progress) IsFinal

func (p *Progress) IsFinal() bool

IsFinal returns whether this is the final progress report.

func (*Progress) String

func (p *Progress) String() string

type Tree

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

Tree is a directory tree representation of the index.

func (*Tree) Dups

func (t *Tree) Dups(dirName string, maxDups, maxLost int) []*Dup

Dups returns directories under dir that contain duplicate data. If maxDups is > 0, at most that many directories are returned. maxLost is the maximum number of unique files that can be lost for a directory to still be considered a duplicate.

func (*Tree) File

func (t *Tree) File(name string) *File

File returns the specified file or nil if it does not exist.

func (*Tree) MarkDup

func (t *Tree) MarkDup(name string) error

MarkDup sets the duplicate flag for a single file or all files under a directory. Files that are already marked are unaffected.

func (*Tree) MarkJunk

func (t *Tree) MarkJunk(name string) error

MarkJunk sets the junk flag for a single file or all files under a directory. Files that are already marked are unaffected.

func (*Tree) MarkKeep

func (t *Tree) MarkKeep(name string) error

MarkKeep sets the keep flag for a single file or all files under a directory. Files that are already marked are unaffected.

func (*Tree) Rescan

func (t *Tree) Rescan(ctx context.Context, fsys fs.FS, errFn func(error), progFn func(*Progress)) (*Index, error)

Rescan updates the index of fsys, skipping the hashing of any files that have identical names, sizes, and modification times. See Scan for more info. Tree t should not be accessed after this operation.

func (*Tree) ToIndex

func (t *Tree) ToIndex() *Index

ToIndex converts from a tree to index representation.

Jump to

Keyboard shortcuts

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