snapraid

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultExecutor

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

DefaultExecutor is the real implementation of Snapraid that shells out.

func (*DefaultExecutor) Diff

func (d *DefaultExecutor) Diff() ([]string, error)

Diff shells out to `snapraid diff`, logs under "diff", and returns all stdout lines. Diff shells out to `snapraid diff`, logs under "diff", and returns all stdout lines.

func (*DefaultExecutor) Scrub

func (d *DefaultExecutor) Scrub() error

Scrub shells out to `snapraid scrub --plan X --older-than Y` under "scrub".

func (*DefaultExecutor) Smart

func (d *DefaultExecutor) Smart() error

Smart shells out to `snapraid smart` and logs each line under "smart".

func (*DefaultExecutor) Sync

func (d *DefaultExecutor) Sync() error

Sync shells out to `snapraid sync` and logs each line under "sync".

func (*DefaultExecutor) Touch

func (d *DefaultExecutor) Touch() error

Touch shells out to `snapraid touch` and logs each line under "touch".

type DiffResult

type DiffResult struct {
	Equal    int      `json:"equal"`                    // number of files that were equal
	Added    []string `json:"added_files,omitempty"`    // list of paths for newly added files
	Removed  []string `json:"removed_files,omitempty"`  // list of paths for removed files
	Updated  []string `json:"updated_files,omitempty"`  // list of paths for updated files
	Moved    []string `json:"moved_files,omitempty"`    // list of paths for moved files
	Copied   []string `json:"copied_files,omitempty"`   // list of paths for copied files
	Restored []string `json:"restored_files,omitempty"` // list of paths for restored files
}

DiffResult holds parsed SnapRAID diff summary and file paths for each change type.

func (DiffResult) HasChanges

func (d DiffResult) HasChanges() bool

HasChanges returns true if any files were added, removed, updated, moved, copied, or restored.

type RunResult

type RunResult struct {
	Timestamp string     `json:"timestamp"`       // RFC3339 timestamp when run started
	Result    DiffResult `json:"result"`          // parsed diff summary + file lists
	Timings   RunTimings `json:"timings"`         // per-step durations + total
	Error     error      `json:"error,omitempty"` // any error that occurred
}

RunResult holds the summary of a completed run.

func (RunResult) HasChanges

func (r RunResult) HasChanges() bool

HasChanges returns true if any files were added/removed/updated/moved/copied/restored.

func (RunResult) WriteJSON

func (r RunResult) WriteJSON(dir string) error

WriteJSON writes the RunResult to a timestamped JSON file in the given directory.

type RunTimings

type RunTimings struct {
	Touch time.Duration `json:"touch"`
	Diff  time.Duration `json:"diff"`
	Sync  time.Duration `json:"sync"`
	Scrub time.Duration `json:"scrub"`
	Smart time.Duration `json:"smart"`
	Total time.Duration `json:"total"`
}

RunTimings captures the duration of each subcommand and the total.

type Runner

type Runner struct {
	Steps      Steps      // which subcommands to run: Touch, Scrub, Smart
	Thresholds Thresholds // numeric limits per change type
	DryRun     bool       // if true, skip sync/scrub/smart

	Logger    *slog.Logger // structured logger for real‐time output
	Timestamp time.Time    // UTC time when Runner was created
	// contains filtered or unexported fields
}

Runner coordinates a full SnapRAID workflow based on its configuration.

func NewRunner

func NewRunner(
	configPath, binaryPath, outputPath string,
	steps Steps,
	thresholds Thresholds,
	scrubPlan, scrubOlder int,
	dryRun bool,
	logger *slog.Logger,
) *Runner

NewRunner constructs a Runner with the given parameters. It installs a DefaultExecutor by default.

func (*Runner) Run

func (r *Runner) Run() RunResult

Run executes the SnapRAID workflow in this order: Touch → Diff → (Sync → Scrub → Smart). It returns a RunResult containing timestamps, parsed diff, per‐step durations, and any error.

type Snapraid

type Snapraid interface {
	Touch() error            // Touch runs `snapraid touch`
	Diff() ([]string, error) // Diff runs `snapraid diff` and returns all output lines
	Sync() error             // Sync runs `snapraid sync`
	Scrub() error            // Scrub runs `snapraid scrub` with plan/older‐than flags
	Smart() error            // Smart runs `snapraid smart`
}

Snapraid defines the five low‐level subcommand methods.

type Steps

type Steps struct {
	Touch bool // Touch enables the "snapraid touch" step.
	Scrub bool // Scrub enables the "snapraid scrub" step.
	Smart bool // Smart enables the "snapraid smart" step.
}

Steps defines which SnapRAID subcommands to run.

type Thresholds

type Thresholds struct {
	Add     int // Add is the maximum number of added files allowed. –1 disables.
	Remove  int // Remove is the maximum number of removed files allowed. –1 disables.
	Update  int // Update is the maximum number of updated files allowed. –1 disables.
	Move    int // Move is the maximum number of moved files allowed. –1 disables.
	Copy    int // Copy is the maximum number of copied files allowed. –1 disables.
	Restore int // Restore is the maximum number of restored files allowed. –1 disables.
}

Thresholds defines numeric limits on detected file changes before blocking sync.

Jump to

Keyboard shortcuts

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