syncer

package
v0.0.0-...-10c04df Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectionBoth = iota
	DirectionRemoteOnly
	DirectionLocalOnly
)

Direction determines which way a sync will move files

DirectionBoth: Sync all files both ways
DirectionRemoteOnly: Only sync files up to the remote location, but not down to local
DirectionLocalOnly: Only sync files to the local location, but not up to the remote
View Source
const (
	ConResOverwrite = iota
	ConResRename
)

ConRes determines the method for Conflict Resolution When two files are found to be in conflict (modified within a set period of each other), this method is used to resolve it Either Overwrite the older file, or Rename the older file

Variables

This section is empty.

Functions

func ProfileSyncCount

func ProfileSyncCount(profileID string) int

ProfileSyncCount returns the number of files currently sycing on the passed in profile

Types

type Profile

type Profile struct {
	Name               string           //Name of the profile
	Direction          int              //direction to sync files
	ConflictResolution int              //Method for handling when there is a sync conflict between two files
	ConflictDuration   time.Duration    //Duration between to file's modified times to determine if there is a conflict
	Ignore             []*regexp.Regexp //List of regular expressions of filepaths to ignore if they match

	Local  Syncer //Local starting point for syncing
	Remote Syncer // Remote starting point for syncing
	// contains filtered or unexported fields
}

Profile is a profile for syncing folders between a local and remote site Conflict resolution happens when two files both have modified dates within the range of the specified ConflictDuration If two files have the same modified date, then there is no conflict, they are seen as the same For example:

if the conflictDuration is 30 seconds and file1 was modified once
at the remote site and once locally within 30 seconds of each other
the conflict resolution option is used, wheter the the oldest file is
overwritten, or if the older file is moved

If there is no conflict and the file's modified dates don't match, the older file is overwritten

func (*Profile) ID

func (p *Profile) ID() string

ID uniquely identifies a profile. Is a combination of Local ID + Remote ID which ensures that the same profile isn't monitored / synced twice

func (*Profile) Start

func (p *Profile) Start() error

Start starts syncing the Profile

func (*Profile) Stop

func (p *Profile) Stop() error

Stop stops the profile from syncing

func (*Profile) Sync

func (p *Profile) Sync(local, remote Syncer) error

Sync Compares the local and remove files and updates the appropriate one

type Syncer

type Syncer interface {
	ID() string                                                 // Unique ID for the file, usually includes the full path to the file
	Path(p *Profile) string                                     // Relative path to the file based on the passed in Profile
	Modified() time.Time                                        // Last time the file was modified
	IsDir() bool                                                // whether or not the file is a dir
	Exists() bool                                               // Whether or not the file exists
	Deleted() bool                                              // If the file doesn't exist was it deleted
	Delete() error                                              // Deletes the file
	Rename() error                                              // Renames the file in the case of a conflict.
	Open() (io.ReadCloser, error)                               // Opens the file for reading
	Write(r io.ReadCloser, size int64, modTime time.Time) error // Writes from the reader to the Syncer, closes reader
	Size() int64                                                // Size of the file
	CreateDir() (Syncer, error)                                 // Create a New Directory based on the non-existant syncer's name
	StartMonitor(*Profile) error                                // Start Monitoring this syncer for changes (Dir's only)
	StopMonitor(*Profile) error                                 // Stop Monitoring this syncer for changes (Dir's only)
}

Syncer is used for comparing two files local or remote to determine which one should be overwritten based on the sync profile rules

Jump to

Keyboard shortcuts

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