Help us shape the future of Go! Take the 2026 Go Developer Survey

sync

package
v0.2.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sync decides sync directions and describes comparison scope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OperationError

func OperationError(conn remote.Client, err error) error

OperationError keeps the operation error and the terminal cause. A failed write may have reached the server, so retrying requires a fresh comparison.

Types

type Decision

type Decision int

Decision represents a user-selectable sync action for a single file.

const (
	DecisionNone Decision = iota
	DecisionUpload
	DecisionDownload
	DecisionDeleteLocal
	DecisionDeleteRemote
)

func AutoDecision

func AutoDecision(s *diff.Session) Decision

AutoDecision returns the most sensible default decision for a diff session.

A 2-second threshold tolerates FAT32 time resolution and minor clock drift. When the files genuinely differ but the timestamps cannot disambiguate the direction — common over FTP/FTPS, where MDTM resolution is coarse and often unreliable — drift defaults to Upload rather than DecisionNone. Returning None here would silently drop the file from "sync all", which is the exact opposite of what a deploy-oriented tool should do.

func NextDecision

func NextDecision(cur Decision, s *diff.Session) Decision

NextDecision cycles through the valid decisions for a session state.

Both sides exist : None → Upload → Download → None
Local only       : None → Upload → DeleteLocal → None
Remote only      : None → Download → DeleteRemote → None

type Failure

type Failure struct {
	Operation string
	Path      string
	Reason    string
	Err       error
}

Failure describes one failed operation.

type Item

type Item struct {
	LocalPath  string
	RemotePath string
	Decision   Decision
}

Item is one planned operation on a local/remote file pair.

type Result

type Result struct {
	Completed []int
	Failures  []Failure
	// Err is context.Canceled after cancellation or the terminal connection
	// failure that stopped the run; nil when every item was attempted.
	Err error
}

Result reports what a run confirmed. Completed and Failures index into the items passed to Run; items after a stop are neither.

func Run

func Run(ctx context.Context, conn remote.Client, root *fs.Root, items []Item, prog *progress.Tracker) Result

Run executes items in order over conn and root. It stops before the next item once ctx is canceled or the connection has failed, and after a certificate failure. Nothing is retried: a write that failed on a dead connection may have reached the server, so its failure says so. prog counts every attempted or skipped item and may be nil.

type ScopeOptions

type ScopeOptions struct {
	IncludeIgnored bool
}

ScopeOptions controls which recursively discovered files enter a comparison.

type ScopeSummary

type ScopeSummary struct {
	Pairs                   int
	Hidden                  int
	IgnoredFilesSkipped     int
	IgnoredDirsSkipped      int
	HardExcludedSkipped     int
	ExplicitIgnoredIncluded int
}

ScopeSummary explains how selections were reduced to comparable file pairs.

Jump to

Keyboard shortcuts

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