seal

package module
v0.0.0-...-32fc0fa Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

README

seal 🦭

Check the integrity of your file archives and backups.

Running it locally

# creates test directory structure, see SetupTestDir
go test ./...

# run the seal command to create _seal.json files
go run ./cmd/seal seal ./testdir

Commands

seal [PATH...]
  • Adds new files and directories to seals.
  • Verifies all existing files against the seal.
  • Raises errors for deleted or modified files.
  • Keeps missing and modified files in the seals.
verify [PATH...]
  • Checks the seal file against the current files.
  • Does a quick check of just metadata first, then a second pass with hashing.
  • Prints all differences in color output.

Documentation

Index

Constants

View Source
const SealFile = ".seal.json"

SealFile is the filepath that is used in every sealed directory.

Variables

View Source
var (
	Before        time.Time
	PrintInterval time.Duration
	IndexFile     string
	PathPrefixes  []string

	WriteLock sync.Mutex
)
View Source
var (
	PrintIndexProgress    = false
	IndexProgressInterval = 15 * time.Second
)
View Source
var (
	PrintSealing    = false
	PrintAllSealing = false
)
View Source
var (
	PrintVerify    = false
	PrintAllVerify = false
)
View Source
var PrintDirsToIndex = true

Functions

func Base64

func Base64(b []byte) string

Base64 encodes a byte slice to a base64 string.

func CompareIndices

func CompareIndices(pathA, pathB string) error

func DirsToIndex

func DirsToIndex(indexPath string, dirs []Dir, basePath string, t StorageType) error

func IndexBenchRead

func IndexBenchRead() error

func IndexBenchWrite

func IndexBenchWrite() error

func IndexPath

func IndexPath(path, indexFile string, prefixes []string) error

func RootCmd

func RootCmd() *cobra.Command

RootCmd is the what that should be executed by the seal command.

Types

type BoltIndex

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

func OpenBoltDB

func OpenBoltDB(indexPath string) (*BoltIndex, error)

func (*BoltIndex) AddDir

func (i *BoltIndex) AddDir(dir *Dir, basePath string) error

func (*BoltIndex) Close

func (i *BoltIndex) Close() error

func (*BoltIndex) LoadAfterHash

func (i *BoltIndex) LoadAfterHash(hash []byte, count int) ([]StoredSeal, error)

type Diff

type Diff struct {
	Identical   bool
	HashChecked bool

	Want *DirSeal
	Have *DirSeal

	NameMatches      bool
	TotalSizeMatches bool
	SHA256Matches    bool

	FilesAdded   []*FileSeal
	FilesMissing []*FileSeal
	FilesChanged []*FileDiff
}

Diff holds the differences between two DirSeals.

func DiffSeals

func DiffSeals(want, have *DirSeal, checkHash bool) *Diff

DiffSeals finds all differences between two DirSeals.

func (*Diff) PrintDifferences

func (d *Diff) PrintDifferences()

PrintDifferences prints the differences between two seals.

type Dir

type Dir struct {
	Path  string
	Depth int

	Seal *DirSeal

	QuickDiff *Diff
	HashDiff  *Diff
}

func SealPath

func SealPath(dirPath string, prefixes []string) ([]Dir, error)

SealPath calculates seals for the given path and all subdirectories and writes them into a seal JSON file per directory.

func VerifyPath

func VerifyPath(dirPath string, printDifferences bool, prefixes []string) ([]Dir, error)

VerifyPath checks all files and directories against the seal JSON files by comparing metadata and hashing file contents.

type DirSeal

type DirSeal struct {
	Name      string
	TotalSize int64
	SHA256    []byte
	Modified  time.Time
	Sealed    time.Time
	// Verified  time.Time
	Files []*FileSeal
}

DirSeal represents a complete seal of the directory including all files and subdirectories.

The SHA256 is calculated by sorting the files by name and appending all sizes as 8 bytes in big endian format as well as the raw bytes of the files SHA256 hash.

func (*DirSeal) UpdateSeal

func (d *DirSeal) UpdateSeal(dirPath string, printChanges bool) error

UpdateSeal writes the seal to the directory in JSON format, joining it with the files seals of an al existing file.

type FileDiff

type FileDiff struct {
	Want *FileSeal
	Have *FileSeal

	IsDirMatches    bool
	SizeMatches     bool
	ModifiedMatches bool
	SHA256Matches   bool
}

FileDiff holds the differences between two FileSeals.

type FileSeal

type FileSeal struct {
	OldVersion bool `json:",omitempty"`
	Deleted    bool `json:",omitempty"`

	Name     string
	IsDir    bool `json:",omitempty"`
	Size     int64
	SHA256   []byte
	Modified time.Time
	Sealed   time.Time
}

FileSeal represents one file inside a directory. If IsDir is true, the fields are populated from the seal file of the subdirectory with this name.

The SHA256 is calculated from the contents of the file.

type IndexStorage

type IndexStorage interface {
	AddDir(dir *Dir, basePath string) error
	LoadAfterHash(hash []byte, count int) ([]StoredSeal, error)
	Close() error
}

type LoadedIndex

type LoadedIndex struct {
	Dirs   []Dir
	ByHash map[string]*StoredSeal
	ByPath map[string]*StoredSeal
}

func LoadIndex

func LoadIndex(indexPath string, t StorageType) (*LoadedIndex, error)

type PebbleIndex

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

func OpenPebble

func OpenPebble(indexPath string) (*PebbleIndex, error)

func (*PebbleIndex) AddDir

func (i *PebbleIndex) AddDir(dir *Dir, basePath string) error

func (*PebbleIndex) Close

func (i *PebbleIndex) Close() error

func (*PebbleIndex) Flush

func (i *PebbleIndex) Flush() error

func (*PebbleIndex) LoadAfterHash

func (i *PebbleIndex) LoadAfterHash(hash []byte, count int) ([]StoredSeal, error)

type SqliteIndex

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

func OpenSqlite

func OpenSqlite(indexPath string) (*SqliteIndex, error)

func (*SqliteIndex) AddDir

func (i *SqliteIndex) AddDir(dir *Dir, basePath string) error

func (*SqliteIndex) Close

func (i *SqliteIndex) Close() error

func (*SqliteIndex) LoadAfterHash

func (i *SqliteIndex) LoadAfterHash(hash []byte, count int) ([]StoredSeal, error)

type StorageType

type StorageType string
const StorageTypeBoltDB StorageType = "boltdb"
const StorageTypePebble StorageType = "pebble"
const StorageTypeSQLite StorageType = "sqlite"

type StoredSeal

type StoredSeal struct {
	Path string
	Dir  *DirSeal
	File *FileSeal
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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