rsync

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgRsyncCallFailedError                  = "RsyncCallFailedError"
	MsgRsyncProcessTerminatedError           = "RsyncProcessTerminatedError"
	MsgRsyncCannotFindFolderSizeOutputError  = "RsyncCannotFindFolderSizeOutputError"
	MsgRsyncCannotParseFolderSizeOutputError = "RsyncCannotParseFolderSizeOutputError"
	MsgRsyncExtractVersionAndProtocolError   = "RsyncExtractVersionAndProtocolError"
)
View Source
const RSYNC_APP_CMD = "rsync"

RSYNC_APP_CMD contains RSYNC console utility system name to run.

Variables

This section is empty.

Functions

func GetPathStatus

func GetPathStatus(ctx context.Context, password *string,
	sourceRSync string, recursive bool) error

GetPathStatus verify that RSYNC source path is valid. For this RSYNC is launched, than exit status is evaluated.

func GetRsyncVersion

func GetRsyncVersion() (version string, protocol string, err error)

GetRsyncVersion run RSYNC to get version and protocol.

func IsCallFailedError added in v0.3.3

func IsCallFailedError(err error) bool

IsCallFailedError check that error able to cast to CallFailedError.

func IsExtractVersionAndProtocolError added in v0.4.0

func IsExtractVersionAndProtocolError(err error) bool

IsExtractVersionAndProtocolError check that error able to cast to ExtractVersionAndProtocolError.

func IsInstalled

func IsInstalled() error

IsInstalled do verify that RSYNC application present in the system.

func IsProcessTerminatedError added in v0.3.3

func IsProcessTerminatedError(err error) bool

IsProcessTerminatedError check that error able to cast to ProcessTerminatedError.

func NormalizeRsyncURL added in v0.3.2

func NormalizeRsyncURL(rsyncURL string) string

NormalizeRsyncURL normalize RSYNC URL by: 1) remove user specification (if found). 2) remove excess '/' chars in path following host.

func ObtainDirFullSize

func ObtainDirFullSize(ctx context.Context, password *string, dir *core.Dir,
	retryCount *int, rsyncProtocol string, log *Logging) (*core.FolderSize, error)

ObtainDirLocalSize parse STDOUT from RSYNC dry-run execution to extract full size of directory.

func ObtainDirLocalSize

func ObtainDirLocalSize(ctx context.Context, password *string, dir *core.Dir,
	retryCount *int, rsyncProtocol string, log *Logging) (*core.FolderSize, error)

ObtainDirLocalSize parse STDOUT from RSYNC dry-run execution to extract local size of directory without nested folders.

func RunRsyncWithRetry

func RunRsyncWithRetry(ctx context.Context, options *Options, log *Logging, stdOut *bytes.Buffer,
	paths core.SrcDstPath) (sessionErr, retryErr, criticalErr error)

RunRsyncWithRetry run RSYNC utility with retry attempts.

func WithDefaultParams

func WithDefaultParams(params []string) []string

WithDefaultParams return list of obligatory options for each run of RSYNC utility.

Types

type CallFailedError added in v0.3.3

type CallFailedError struct {
	ExitCode    int
	Description string
}

CallFailedError denote a situation when RSYNC execution completed with non-zero exit code.

func NewCallFailedError added in v0.3.3

func NewCallFailedError(exitCode int, stdErr *bytes.Buffer) *CallFailedError

NewCallFailedError creates error object based on ExitCode from RSYNC. Use STDERR variable to extract more human readable error description.

func (*CallFailedError) Error added in v0.3.3

func (v *CallFailedError) Error() string

type ErrorHook

type ErrorHook struct {
	Call          ErrorHookCall
	PredictedSize *core.FolderSize
}

ErrorHook contains call and predicted size to work around RSYNC issues caused by out of disk space case.

func NewErrorHook added in v0.3.2

func NewErrorHook(call ErrorHookCall, predictedSize core.FolderSize) *ErrorHook

type ErrorHookCall added in v0.3.2

type ErrorHookCall func(err error, paths core.SrcDstPath, predictedSize *core.FolderSize,
	repeated int, retryLeft int) (newRetryLeft int, criticalError error)

ErrorHookCall is a delegate used to work around RSYNC issues caused by out of disk space case.

type ExtractVersionAndProtocolError added in v0.4.0

type ExtractVersionAndProtocolError struct {
}

ExtractVersionAndProtocolError denote a situation when attempt to extract rsync version/protocol has failed, and version and protocol are undefined. This error is not critical (in the main) and should not lead to app failure.

func (*ExtractVersionAndProtocolError) Error added in v0.4.0

type Logging

type Logging struct {
	EnableLog          bool
	EnableIntensiveLog bool
	Log                logger.PackageLog
}

Logging keep settings whether we need to log RSYNC utility functioning. We can log only RSYNC calls, but also STDOUT output for intensive log.

type Options

type Options struct {
	RetryCount int
	Params     []string
	ErrorHook  *ErrorHook
	Password   *string
}

Options keep settings for RSYNC call. Settings include: retry count, parameters, ErrorHook object for recover attempt if issue thrown.

func NewOptions

func NewOptions(params []string) *Options

func (*Options) AddParams

func (v *Options) AddParams(params ...string) *Options

AddParams add RSYNC command line options.

func (*Options) SetAuthPassword added in v0.3.2

func (v *Options) SetAuthPassword(password *string) *Options

SetAuthPassword set password to use in RSYNC call to get data from authenticated (password protected) RSYNC module. Read option "secrets file" at https://linux.die.net/man/5/rsyncd.conf, which describe how to protect RSYNC data source with password.

func (*Options) SetErrorHook

func (v *Options) SetErrorHook(errorHook *ErrorHook) *Options

SetErrorHook define callback function to run, if RESYNC utility exited with error code <> 0. Such callback might suggest issue source and make recommendation to user via UI to resolve the issue before following retry.

func (*Options) SetRetryCount

func (v *Options) SetRetryCount(retryCount *int) *Options

SetRetryCount set retry count for repeated call in case of error return results (exit code <> 0).

type ProcessTerminatedError added in v0.3.3

type ProcessTerminatedError struct {
}

ProcessTerminatedError denote a situation with termination pending.

func (*ProcessTerminatedError) Error added in v0.3.3

func (v *ProcessTerminatedError) Error() string

Jump to

Keyboard shortcuts

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