Documentation
¶
Overview ¶
Package sync pushes a local directory tree into a B2 bucket prefix. The local tree is the source of truth: a file differing under the selected comparison policy overwrites the cloud version, even when the cloud version is newer. This package has no skip-newer or replace-newer mode, does not delete cloud-only files, and does not resume interrupted large-file uploads. Symlinks below the root are not followed; a symlinked root is resolved before the walk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompareMode ¶
type CompareMode int
CompareMode selects how a local file is compared with a destination object.
const ( // CompareModTime compares modification times at millisecond resolution. // It is the default; matching times are unchanged even if sizes differ. CompareModTime CompareMode = iota // CompareSize compares file sizes, ignoring modification times. CompareSize // CompareNone compares names only: an existing name is always skipped. CompareNone // CompareSHA1 compares checksums, ignoring size and modification time. // A missing destination checksum requires uploading the local file. CompareSHA1 )
type Option ¶
type Option func(*options)
Option configures Sync.
func WithCompare ¶
func WithCompare(mode CompareMode) Option
WithCompare selects the comparison policy. The default is CompareModTime. Different comparison options in one Sync call are rejected.
func WithConcurrency ¶
WithConcurrency sets the maximum number of files uploaded at once. Different concurrency options in one Sync call are rejected.
func WithDryRun ¶
func WithDryRun() Option
WithDryRun reports planned uploads without writing to B2.
type Result ¶
Result lists relative paths uploaded, skipped, or failed. In a dry run, Uploaded is the planned upload list and BytesUploaded is zero.
func Sync ¶
func Sync(ctx context.Context, bucket *b2.Bucket, prefix, localRoot string, opts ...Option) (*Result, error)
Sync pushes files below localRoot into bucket under prefix. The local tree is the source of truth: a local file differing under the comparison policy overwrites the cloud copy even when its modification time is older; skip-newer and replace-newer policies are not available. Matching files are skipped, and cloud objects are never deleted. Symlinks below the root are not followed; a symlinked root is followed. Changed large files are re-uploaded in full, without resuming a previous upload. Per-file failures are returned in Result.Failed along with an aggregate error; other files continue. Linux and macOS reject replaced FIFOs without blocking; Windows does not follow a final reparse-point replacement. On other platforms, Sync returns a nil result and an error wrapping errors.ErrUnsupported with GOOS/GOARCH context before walking local files or making B2 requests. The package still builds on those platforms.