fsdiff

package
v0.0.0-...-ee9d8c9 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const SEP = "/"

Variables

This section is empty.

Functions

This section is empty.

Types

type DirMeta

type DirMeta struct {
	Name  string
	Mode  fs.FileMode
	Files map[string]*FileMeta
	Dirs  map[string]*DirMeta
}

func NewDirMeta

func NewDirMeta(name string) *DirMeta

func (*DirMeta) AddDir

func (d *DirMeta) AddDir(dm *DirMeta)

Add an existing DirMeta to this directory

func (*DirMeta) AddFile

func (d *DirMeta) AddFile(fm *FileMeta)

Add an existing FileMeta to this directory

func (*DirMeta) CountTree

func (d *DirMeta) CountTree() int

Returns the total number of files and directories in this tree. This may be useful in determining progress indicators.

func (*DirMeta) GetDir

func (d *DirMeta) GetDir(fpath string) *DirMeta

func (*DirMeta) GetFile

func (d *DirMeta) GetFile(fpath string) *FileMeta

func (*DirMeta) MakeDir

func (d *DirMeta) MakeDir(fpath string) *DirMeta

Similar to the 'mkdir -p' command this will return a new directory at the given path, creating missing directories if necessary.

type DirMetaBuilder

type DirMetaBuilder struct {
	// Root of the file metadata tree
	Root *DirMeta
	// Any *recoverable* errors encountered when trying to read a path will be
	// added here, things like permission errors or read errors. Just because
	// one file can't be read doesn't mean all files can't.
	PathErrors map[string]error
	// An array of absolute paths that will be ignored
	Excludes []string
	// contains filtered or unexported fields
}

Helper for filling out a DirMeta tree from a filesystem, archive, or other source.

func NewDirMetaBuilder

func NewDirMetaBuilder(root *DirMeta) *DirMetaBuilder

func (*DirMetaBuilder) Add

func (b *DirMetaBuilder) Add(fpath string, d fs.DirEntry, rd io.Reader, inErr error) error

Similar to fs.WalkDirFunc but also receives a reader to read the contents of the file or nil if the entry is a directory.

func (*DirMetaBuilder) AddFs

func (b *DirMetaBuilder) AddFs(fsys fs.FS) error

Calls fs.WalkDir on fsys and then adds the files and directories using b.Add.

func (*DirMetaBuilder) AddTar

func (b *DirMetaBuilder) AddTar(tr *tar.Reader) error

Iterates through the tar file and calls b.Add for each entry.

func (*DirMetaBuilder) HasErrors

func (b *DirMetaBuilder) HasErrors() bool

func (*DirMetaBuilder) HashReader

func (b *DirMetaBuilder) HashReader(rd io.Reader) (int64, string, error)

Hashes the contents of a reader, returning the total size, hash, and any error.

type FileMeta

type FileMeta struct {
	Name string
	Mode fs.FileMode
	// Sha256 hash of the file contents
	Hash string
	// Size of the file
	Size int64
}

func (*FileMeta) IsSame

func (fm *FileMeta) IsSame(rhs *FileMeta) bool

type FsDiff

type FsDiff struct {
	// Full paths of files that were added
	Added []string
	// Full paths of files that were removed
	Removed []string
	// Full paths of files that were modified
	Modified []string
}

A filesystem-diff, determines a full list of files that have been added, modified, and removed.

func NewFsDiff

func NewFsDiff() *FsDiff

func (*FsDiff) Compare

func (d *FsDiff) Compare(lt *DirMeta, rt *DirMeta) error

Compare two directory metadata objects, building a full diff of them.

func (*FsDiff) GetAddedModified

func (d *FsDiff) GetAddedModified() []string

Returns the combied list of added and modified files

Jump to

Keyboard shortcuts

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