diff

package
v0.0.1-beta7 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package diff provides the functionality for ajfs diff command.

Index

Constants

View Source
const (
	ChangedNothing = 0         // Nothing changed
	ChangedMode    = 1 << iota // The path's type and or permissions has changed
	ChangedSize                // The size has changed
	ChangedModTime             // The last modification time has changed
	ChangedHash                // The hash is different
)
View Source
const (
	FilterNoOp           = 0         // Don't apply a filter
	FilterDirs           = 1 << iota // Directories
	FilterFiles                      // Files
	FilterTypeLeft                   // LHS only (mutually exclusive with FilterOnlyRight)
	FilterTypeRight                  // RHS only
	FilterTypeChanged                // Both sides but has changes
	FilterChangedMode                // The path's type and or permissions has changed
	FilterChangedSize                // The size has changed
	FilterChangedModTime             // The last modification time has changed
	FilterChangedHash                // The hash is different

	FilterChangedMask = FilterChangedMode | FilterChangedSize | FilterChangedModTime | FilterChangedHash
)

Variables

View Source
var SkipAll = errors.New("skip all") //nolint:staticcheck //ST1012: not an error and is more readable

Indicates to Compare to stop processing differences.

Functions

func Compare

func Compare(lhsPath string, rhsPath string,
	includeFilters []FilterFlags, excludeFilters []FilterFlags,
	fn CompareFn) error

Compare the differences between two ajfs database files. fn Will be called for each difference that is found. If fn returns SkipAll then the process will be stopped and nil will be returned as the error.

func CompareDatabases

func CompareDatabases(lhs *db.DatabaseFile, rhs *db.DatabaseFile, onlyLHS bool, fn CompareFn) error

func Run

func Run(cfg Config) error

Process the ajfs diff command.

Types

type ChangedFlags

type ChangedFlags uint8

Describe what has changed for an item that exists on both sides.

func (ChangedFlags) FilterFlagsMask

func (f ChangedFlags) FilterFlagsMask() FilterFlags

func (ChangedFlags) HashChanged

func (f ChangedFlags) HashChanged() bool

func (ChangedFlags) ModTimeChanged

func (f ChangedFlags) ModTimeChanged() bool

func (ChangedFlags) ModeChanged

func (f ChangedFlags) ModeChanged() bool

func (ChangedFlags) SizeChanged

func (f ChangedFlags) SizeChanged() bool

type CompareFn

type CompareFn func(d Diff) error

Called by Compare for each difference that was found. Return SkipAll to stop the process.

type Config

type Config struct {
	config.CommonConfig

	LhsPath string
	RhsPath string

	IncludeFilters []FilterFlags
	ExcludeFilters []FilterFlags

	Fn CompareFn
}

Config for the ajfs diff command.

type Diff

type Diff struct {
	Type    Type         // Type of difference
	Id      path.Id      // Identifier of the path info item
	Path    string       // Path of the item
	IsDir   bool         // Is this a directory
	Changed ChangedFlags // What was changed
	Size    uint64       // Size of the item. If the item exists on both sides, then this would be the size of the LHS item
}

Describe a difference between the LHS and RHS databases.

func (Diff) FilterFlagsMask

func (d Diff) FilterFlagsMask() FilterFlags

func (*Diff) String

func (d *Diff) String() string

Stringer implementation.

type DiffStats

type DiffStats struct {
	LeftOnly   int // Count of left hand side only items
	RightOnly  int // Count of right hand side only items
	Changed    int // Count of changed items
	NotChanged int // Count of items that exist in both sides and that is unchanged

	Files int // Count of files
	Dirs  int // Count of directories

	ModeChanged    int // Count of items where the mode has changed
	SizeChanged    int // Count of items where the size has changed
	ModTimeChanged int // Count of items where the last modification time changed
	HashChanged    int // Count of items where the hash has changed

	Fn CompareFn // The compare function to be called
}

DiffStats can be used to get some statistics out of a diff.

func (*DiffStats) Compare

func (ds *DiffStats) Compare(d Diff) error

Compare function that will update the stats.

type FilterFlags

type FilterFlags uint16

Flags used to decide which items to be included or excluded in a diff.

func ParseFilterFlags

func ParseFilterFlags(input string) (FilterFlags, error)

func ParseFilterFlagsArray

func ParseFilterFlagsArray(input []string) ([]FilterFlags, error)

func (FilterFlags) ChangedFlagsMask

func (f FilterFlags) ChangedFlagsMask() ChangedFlags

func (FilterFlags) String

func (f FilterFlags) String() string

func (FilterFlags) Validate

func (f FilterFlags) Validate() error

type Type

type Type int

Describe the type of difference.

const (
	TypeNothing        = 0        // Nothing changed
	TypeLeftOnly  Type = 1 + iota // Only on the LHS (same as having been removed from the RHS)
	TypeRightOnly                 // Only on the RHS (same as having been added in the RHS)
	TypeChanged                   // Some of the file's meta data or the hash have been changed
)

Jump to

Keyboard shortcuts

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