bisync

package
v0.0.0-...-b4aeae5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

Package bisync implements bisync Copyright (c) 2017-2020 Chris Nelson

Package bisync implements bisync Copyright (c) 2017-2020 Chris Nelson

Package bisync implements bisync Copyright (c) 2017-2020 Chris Nelson

Package bisync implements bisync Copyright (c) 2017-2020 Chris Nelson Contributions to original python version: Hildo G. Jr., e2t, kalemas, silenceleaf

Index

Constants

View Source
const (
	DefaultMaxDelete     int    = 50
	DefaultCheckFilename string = "RCLONE_TEST"
)

Default values

View Source
const ListingHeader = "# bisync listing v1 from"

ListingHeader defines first line of a listing

Variables

View Source
var Colors bool // Colors controls whether terminal colors are enabled
View Source
var ConflictLoserList = Opt.ConflictLoser.Help()

ConflictLoserList is a list of --conflict-loser flag choices used in the help

View Source
var ConflictResolveList = Opt.ConflictResolve.Help()

ConflictResolveList is a list of --conflict-resolve flag choices used in the help

View Source
var DefaultWorkdir = filepath.Join(config.GetCacheDir(), "bisync")

DefaultWorkdir is default working directory

View Source
var ErrBisyncAborted = errors.New("bisync aborted")

ErrBisyncAborted signals that bisync is aborted and forces exit code 2

View Source
var TZ = time.UTC

TZ defines time zone used in listings

Functions

func Bisync

func Bisync(ctx context.Context, fs1, fs2 fs.Fs, optArg *Options) (err error)

Bisync handles lock file, performs bisync run and checks exit status

func CheckFn

func CheckFn(ctx context.Context, dst, src fs.Object) (differ bool, noHash bool, err error)

CheckFn is a slightly modified version of Check

func Color

func Color(style string, s string) string

Color handles terminal colors for bisync

func Concat

func Concat[S ~[]E, E any](ss ...S) S

Concat returns a new slice concatenating the passed in slices.

func ConvertPrecision

func ConvertPrecision(Modtime time.Time, dst fs.Fs) time.Time

ConvertPrecision returns the Modtime rounded to Dest's precision if lower, otherwise unchanged Need to use the other fs's precision (if lower) when copying Note: we need to use Truncate rather than Round so that After() is reliable. (2023-11-02 20:22:45.552679442 +0000 < UTC 2023-11-02 20:22:45.553 +0000 UTC)

func CryptCheckFn

func CryptCheckFn(ctx context.Context, dst, src fs.Object) (differ bool, noHash bool, err error)

CryptCheckFn is a slightly modified version of CryptCheck

func DownloadCheckFn

func DownloadCheckFn(ctx context.Context, a, b fs.Object) (differ bool, noHash bool, err error)

DownloadCheckFn is a slightly modified version of Check with --download

func FsPathIfAny

func FsPathIfAny(x fs.DirEntry) string

FsPathIfAny handles type assertions and returns a formatted bilib.FsPath if valid, otherwise ""

func ID

func ID(o fs.Object) string

ID returns the ID of the Object if known, or "" if not

func ReverseCryptCheckFn

func ReverseCryptCheckFn(ctx context.Context, dst, src fs.Object) (differ bool, noHash bool, err error)

ReverseCryptCheckFn is like CryptCheckFn except src and dst are switched result: src is crypt, dst is non-crypt

func SuffixName

func SuffixName(ctx context.Context, remote, suffix string) string

SuffixName adds the current --conflict-suffix to the remote, obeying --suffix-keep-extension if set It is a close cousin of operations.SuffixName, but we don't want to use ci.Suffix for this because it might be used for --backup-dir.

func WhichCheck

func WhichCheck(ctx context.Context, opt *operations.CheckOpt) *operations.CheckOpt

WhichCheck determines which CheckFn we should use based on the Fs types It is more robust and accurate than Check because it will fallback to CryptCheck or DownloadCheck instead of --size-only! it returns the *operations.CheckOpt with the CheckFn set.

func WhichEqual

func WhichEqual(ctx context.Context, src, dst fs.Object, Fsrc, Fdst fs.Fs) bool

WhichEqual is similar to WhichCheck, but checks a single object. Returns true if the objects are equal, false if they differ or if we don't know

func WriteResults

func WriteResults(ctx context.Context, sigil operations.Sigil, src, dst fs.DirEntry, err error)

WriteResults is Bisync's LoggerFn

Types

type CheckSyncMode

type CheckSyncMode int

CheckSyncMode controls when to compare final listings

const (
	CheckSyncTrue  CheckSyncMode = iota // Compare final listings (default)
	CheckSyncFalse                      // Disable comparison of final listings
	CheckSyncOnly                       // Only compare listings from the last run, do not sync
)

CheckSync modes

func (*CheckSyncMode) Set

func (x *CheckSyncMode) Set(s string) error

Set a CheckSync mode from a string

func (CheckSyncMode) String

func (x CheckSyncMode) String() string

func (*CheckSyncMode) Type

func (x *CheckSyncMode) Type() string

Type of the CheckSync value

type CompareOpt

type CompareOpt = struct {
	Modtime          bool
	Size             bool
	Checksum         bool
	HashType1        hash.Type
	HashType2        hash.Type
	NoSlowHash       bool
	SlowHashSyncOnly bool
	SlowHashDetected bool
	DownloadHash     bool
}

CompareOpt describes the Compare options in force

type ConflictLoserAction

type ConflictLoserAction = fs.Enum[conflictLoserChoices]

ConflictLoserAction describes possible actions to take on the loser of a sync conflict

const (
	ConflictLoserSkip     ConflictLoserAction = iota // Reserved as zero but currently unused
	ConflictLoserNumber                              // file.conflict1, file.conflict2, file.conflict3, etc.
	ConflictLoserPathname                            // file.path1, file.path2
	ConflictLoserDelete                              // delete the loser, keep winner only
)

Supported --conflict-loser actions

type Options

type Options struct {
	Resync                bool   // whether or not this is a resync
	ResyncMode            Prefer // which mode to use for resync
	CheckAccess           bool
	CheckFilename         string
	CheckSync             CheckSyncMode
	CreateEmptySrcDirs    bool
	RemoveEmptyDirs       bool
	MaxDelete             int // percentage from 0 to 100
	Force                 bool
	FiltersFile           string
	Workdir               string
	OrigBackupDir         string
	BackupDir1            string
	BackupDir2            string
	DryRun                bool
	NoCleanup             bool
	SaveQueues            bool // save extra debugging files (test only flag)
	IgnoreListingChecksum bool
	Resilient             bool
	Recover               bool
	TestFn                TestFunc // test-only option, for mocking errors
	Compare               CompareOpt
	CompareFlag           string
	DebugName             string
	MaxLock               time.Duration
	ConflictResolve       Prefer
	ConflictLoser         ConflictLoserAction
	ConflictSuffixFlag    string
	ConflictSuffix1       string
	ConflictSuffix2       string
}

Options keep bisync options

var Opt Options

Opt keeps command line options

type Prefer

type Prefer = fs.Enum[preferChoices]

Prefer describes strategies for resolving sync conflicts

const (
	PreferNone Prefer = iota
	PreferPath1
	PreferPath2
	PreferNewer
	PreferOlder
	PreferLarger
	PreferSmaller
)

Supported --conflict-resolve strategies

type Results

type Results struct {
	Src      string
	Dst      string
	Name     string
	AltName  string
	Size     int64
	Modtime  time.Time
	Hash     string
	Flags    string
	Sigil    operations.Sigil
	Err      error
	Winner   operations.Winner
	IsWinner bool
	IsSrc    bool
	IsDst    bool
	Origin   string
}

Results represents a pair of synced files, as reported by the LoggerFn Bisync uses this to determine what happened during the sync, and modify the listings accordingly

func ReadResults

func ReadResults(results io.Reader) []Results

ReadResults decodes the JSON data from WriteResults

type ResultsSlice

type ResultsSlice []Results

ResultsSlice is a slice of Results (obviously)

type TestFunc

type TestFunc func()

TestFunc allows mocking errors during tests

Directories

Path Synopsis
Package bilib provides common stuff for bisync and bisync_test
Package bilib provides common stuff for bisync and bisync_test

Jump to

Keyboard shortcuts

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