sync

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitPatterns

func SplitPatterns(raw string) []string

SplitPatterns parses a comma/newline separated pattern list.

Types

type Action

type Action struct {
	Type            ActionType
	RelativePath    string
	SourcePath      string
	DestinationPath string
	Size            int64
	SourceModified  time.Time
}

Action is one immutable plan item.

type ActionType

type ActionType string

ActionType describes a single sync action in a generated plan.

const (
	ActionCopy   ActionType = "copy"
	ActionUpdate ActionType = "update"
	ActionDelete ActionType = "delete"
	ActionSkip   ActionType = "skip"
)

type CompareMode

type CompareMode string

CompareMode controls how source and destination files are compared.

const (
	CompareMTimeSize      CompareMode = "mtime_size"
	CompareSizeOnly       CompareMode = "size_only"
	CompareExactTimestamp CompareMode = "exact_timestamps"
	CompareChecksum       CompareMode = "checksum"
)

type Counts

type Counts struct {
	Copy   int
	Update int
	Delete int
	Skip   int
}

Counts is an action summary.

func (Counts) Total

func (c Counts) Total() int

Total returns all action counts combined.

type ExecuteOptions

type ExecuteOptions struct {
	Concurrency    int
	CompletedPaths map[string]struct{} // paths to skip (already completed from prior run)
	MaxRetries     int
	RetryBackoff   time.Duration
	BandwidthLimit int64 // bytes per second, 0 = unlimited
}

ExecuteOptions customizes execution behavior.

type Failure

type Failure struct {
	Action Action
	Err    error
}

Failure captures a failed execution action.

type IndexedFile

type IndexedFile struct {
	RelativePath string
	FullPath     string
	Size         int64
	Modified     time.Time
	Checksum     string // optional: content hash if available
}

IndexedFile is a normalized file entry keyed by relative path.

type Matcher

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

Matcher evaluates include/exclude rules with "last match wins" semantics.

func NewMatcher

func NewMatcher(opts Options) Matcher

NewMatcher builds an ordered matcher from options.

func (Matcher) Allowed

func (m Matcher) Allowed(relPath string) bool

Allowed returns whether a relative path should be part of sync logic. Default is allow unless at least one rule matches and the last match is exclude.

type Options

type Options struct {
	Direction                  SyncDirection
	CompareMode                CompareMode
	Delete                     bool
	DryRun                     bool
	NoOverwrite                bool
	IncludeRules               []string
	ExcludeRules               []string
	Concurrency                int
	CaseInsensitiveDestination bool
	ExactTimestampsAllowed     bool
	MaxRetries                 int           // max retry attempts per action (0 = no retry)
	RetryBackoff               time.Duration // initial backoff duration (doubles each retry)
	BandwidthLimit             int64         // bytes per second, 0 = unlimited
}

Options configures planner and executor behavior.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns safe defaults for sync planning and execution.

func (Options) Normalize

func (o Options) Normalize() Options

Normalize fills default values and trims rules.

func (Options) Validate

func (o Options) Validate() error

Validate checks whether options are semantically valid.

type Plan

type Plan struct {
	SourceRoot      string
	DestinationRoot string
	Options         Options
	Actions         []Action
	Counts          Counts
	BytesToTransfer int64
	Warnings        []string
}

Plan is the immutable output of planner generation.

func BuildPlan

func BuildPlan(ctx context.Context, src backend.Backend, sourceRoot string, dst backend.Backend, destinationRoot string, opts Options, onProgress func(PlanningProgress)) (Plan, error)

BuildPlan scans source/destination and produces an immutable sync plan.

func (Plan) RunnableActions

func (p Plan) RunnableActions() []Action

RunnableActions returns only mutating actions.

type PlanningProgress

type PlanningProgress struct {
	Phase        string
	Scanned      int
	BytesScanned int64
}

PlanningProgress is emitted during scan/planning phases.

type Progress

type Progress struct {
	Completed  int
	Total      int
	Action     Action
	Err        error
	BytesDone  int64 // bytes transferred so far for the current action
	BytesTotal int64 // total bytes for the current action (= Action.Size)
}

Progress is emitted by the executor as actions complete or as bytes transfer. When BytesDone > 0 and Err == nil, this is a byte-level progress update for the current action. Completed reflects the number of already-finished actions (not counting the in-progress one), so the UI can compute overall progress as (Completed + BytesDone/BytesTotal) / Total.

type Rule

type Rule struct {
	Type    RuleType
	Pattern string
}

Rule is one ordered matcher rule.

type RuleType

type RuleType int

RuleType marks include vs exclude rules.

const (
	RuleExclude RuleType = iota
	RuleInclude
)

type Summary

type Summary struct {
	DryRun         bool
	Planned        Counts
	Applied        Counts
	Completed      int
	Total          int
	Failures       []Failure
	StartedAt      time.Time
	EndedAt        time.Time
	CompletedPaths map[string]struct{} // successfully completed relative paths (for resume)
}

Summary captures a sync execution result.

func ExecutePlan

func ExecutePlan(ctx context.Context, src backend.Backend, dst backend.Backend, plan Plan, opts ExecuteOptions, onProgress func(Progress)) (Summary, error)

ExecutePlan runs a prebuilt sync plan and returns an execution summary.

func (Summary) Duration

func (s Summary) Duration() time.Duration

Duration returns execution wall-clock duration.

func (Summary) Failed

func (s Summary) Failed() int

Failed returns the number of failed actions.

type SyncDirection

type SyncDirection string

SyncDirection describes panel-to-panel sync direction.

const (
	DirectionLeftToRight SyncDirection = "left_to_right"
	DirectionRightToLeft SyncDirection = "right_to_left"
)

Jump to

Keyboard shortcuts

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