sync

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package sync provides the core data structures and algorithms used by Mutagen. It does not provide facilities for data transport or session management, which are instead provided by the rsync and session packages, respectively.

Index

Constants

This section is empty.

Variables

View Source
var DefaultVCSIgnores = []string{
	".git/",
	".svn/",
	".hg/",
	".bzr/",
	"_darcs/",
}

DefaultVCSIgnores is the default set of ignores to use when ignoring VCS directories.

View Source
var EntryKind_name = map[int32]string{
	0: "Directory",
	1: "File",
	2: "Symlink",
}
View Source
var EntryKind_value = map[string]int32{
	"Directory": 0,
	"File":      1,
	"Symlink":   2,
}
View Source
var IgnoreVCSMode_name = map[int32]string{
	0: "IgnoreVCSDefault",
	1: "IgnoreVCS",
	2: "PropagateVCS",
}
View Source
var IgnoreVCSMode_value = map[string]int32{
	"IgnoreVCSDefault": 0,
	"IgnoreVCS":        1,
	"PropagateVCS":     2,
}
View Source
var SymlinkMode_name = map[int32]string{
	0: "SymlinkDefault",
	1: "SymlinkIgnore",
	2: "SymlinkPortable",
	3: "SymlinkPOSIXRaw",
}
View Source
var SymlinkMode_value = map[string]int32{
	"SymlinkDefault":  0,
	"SymlinkIgnore":   1,
	"SymlinkPortable": 2,
	"SymlinkPOSIXRaw": 3,
}

Functions

func Reconcile

func Reconcile(ancestor, alpha, beta *Entry) ([]*Change, []*Change, []*Change, []*Conflict)

Reconcile performs a recursive three-way merge and generates a list of changes for the ancestor, alpha, and beta, as well as a list of conflicts.

func Scan

func Scan(root string, hasher hash.Hash, cache *Cache, ignores []string, ignoreCache IgnoreCache, symlinkMode SymlinkMode) (*Entry, bool, bool, *Cache, IgnoreCache, error)

Scan provides recursive filesystem scanning facilities for synchronization roots.

func Transition

func Transition(
	root string,
	transitions []*Change,
	cache *Cache,
	symlinkMode SymlinkMode,
	recomposeUnicode bool,
	provider Provider,
) ([]*Entry, []*Problem)

Transition provides recursive filesystem transitioning facilities for synchronization roots, allowing the application of changes after reconciliation.

func TransitionDependencies

func TransitionDependencies(transitions []*Change) (map[string][]byte, error)

TransitionDependencies analyzes a list of transitions and determines the file paths (and their corresponding digests) that will need to be provided in order to apply the transitions using Transition.

func ValidIgnorePattern

func ValidIgnorePattern(pattern string) bool

ValidIgnorePattern checks whether or not a given pattern is a valid ignore specification.

Types

type Archive

type Archive struct {
	Root                 *Entry   `protobuf:"bytes,1,opt,name=root,proto3" json:"root,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Archive is a wrapper around Entry that allows identification of non-existent roots when serializing. In-memory, a nil-Entry (that arrives without any error) represents an absence of content on the filesystem. Unfortunately, there is no way to represent that as an encoded message (an empty byte slice would successfully decode to an empty directory entry). By adding a level of indirection that allows for an unset root entry, we can encode Entry messages in a way that allows us to represent absence.

func (*Archive) Descriptor

func (*Archive) Descriptor() ([]byte, []int)

func (*Archive) GetRoot

func (m *Archive) GetRoot() *Entry

func (*Archive) ProtoMessage

func (*Archive) ProtoMessage()

func (*Archive) Reset

func (m *Archive) Reset()

func (*Archive) String

func (m *Archive) String() string

func (*Archive) XXX_DiscardUnknown

func (m *Archive) XXX_DiscardUnknown()

func (*Archive) XXX_Marshal

func (m *Archive) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Archive) XXX_Merge

func (dst *Archive) XXX_Merge(src proto.Message)

func (*Archive) XXX_Size

func (m *Archive) XXX_Size() int

func (*Archive) XXX_Unmarshal

func (m *Archive) XXX_Unmarshal(b []byte) error

type Cache

type Cache struct {
	// Entries is a map from scan path to cache entry.
	Entries              map[string]*CacheEntry `` /* 155-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}               `json:"-"`
	XXX_unrecognized     []byte                 `json:"-"`
	XXX_sizecache        int32                  `json:"-"`
}

Cache provides a store for file metadata and digets to allow for efficient rescans.

func (*Cache) Descriptor

func (*Cache) Descriptor() ([]byte, []int)

func (*Cache) EnsureValid

func (c *Cache) EnsureValid() error

EnsureValid ensures that Cache's invariants are respected.

func (*Cache) GenerateReverseLookupMap added in v0.5.0

func (c *Cache) GenerateReverseLookupMap() (*ReverseLookupMap, error)

GenerateReverseLookupMap creates a reverse lookup map from a cache.

func (*Cache) GetEntries

func (m *Cache) GetEntries() map[string]*CacheEntry

func (*Cache) ProtoMessage

func (*Cache) ProtoMessage()

func (*Cache) Reset

func (m *Cache) Reset()

func (*Cache) String

func (m *Cache) String() string

func (*Cache) XXX_DiscardUnknown

func (m *Cache) XXX_DiscardUnknown()

func (*Cache) XXX_Marshal

func (m *Cache) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Cache) XXX_Merge

func (dst *Cache) XXX_Merge(src proto.Message)

func (*Cache) XXX_Size

func (m *Cache) XXX_Size() int

func (*Cache) XXX_Unmarshal

func (m *Cache) XXX_Unmarshal(b []byte) error

type CacheEntry

type CacheEntry struct {
	// Mode stores the value of the Go os package's FileMode type. The meaning
	// of this value is defined to be stable (even if we'd have to implement its
	// computation ourselves when porting to another language), so it's safe to
	// use, and it's a relatively sane implementation based on POSIX mode bits.
	// This information is currently used in scans and transitions, but only the
	// type and executability bits are really used (or at least necessary) at
	// the moment. It's not clear whether or not we'll eventually need the other
	// permission bits, and it might be possible to get away with a type
	// enumeration instead. This might be easier than trying to replicate
	// FileMode values if moving to another language, though I'm not sure that
	// would be too difficult. But I suppose it's better to just have this
	// additional mode information available for the sake of generality and
	// extensibility. We can always drop it later, but we can't add it back. It
	// may (I'm not exactly sure how) come in useful if we want to implement
	// permission propagation or need a better change detection heuristic. At
	// the moment though, it's highly unlikely that we'll switch away from Go,
	// and I'm willing to live with this slightly "unclean" design, especially
	// given its potential and the relative ease of deprecating it if necessary.
	Mode uint32 `protobuf:"varint,1,opt,name=mode,proto3" json:"mode,omitempty"`
	// ModificationTime is the cached modification time.
	ModificationTime *timestamp.Timestamp `protobuf:"bytes,2,opt,name=modificationTime,proto3" json:"modificationTime,omitempty"`
	// Size is the cached size.
	Size uint64 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"`
	// Digest is the cached digest for file entries.
	Digest               []byte   `protobuf:"bytes,9,opt,name=digest,proto3" json:"digest,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

CacheEntry represents cache data for a file on disk.

func (*CacheEntry) Descriptor

func (*CacheEntry) Descriptor() ([]byte, []int)

func (*CacheEntry) GetDigest

func (m *CacheEntry) GetDigest() []byte

func (*CacheEntry) GetMode

func (m *CacheEntry) GetMode() uint32

func (*CacheEntry) GetModificationTime

func (m *CacheEntry) GetModificationTime() *timestamp.Timestamp

func (*CacheEntry) GetSize

func (m *CacheEntry) GetSize() uint64

func (*CacheEntry) ProtoMessage

func (*CacheEntry) ProtoMessage()

func (*CacheEntry) Reset

func (m *CacheEntry) Reset()

func (*CacheEntry) String

func (m *CacheEntry) String() string

func (*CacheEntry) XXX_DiscardUnknown

func (m *CacheEntry) XXX_DiscardUnknown()

func (*CacheEntry) XXX_Marshal

func (m *CacheEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CacheEntry) XXX_Merge

func (dst *CacheEntry) XXX_Merge(src proto.Message)

func (*CacheEntry) XXX_Size

func (m *CacheEntry) XXX_Size() int

func (*CacheEntry) XXX_Unmarshal

func (m *CacheEntry) XXX_Unmarshal(b []byte) error

type Change

type Change struct {
	Path                 string   `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
	Old                  *Entry   `protobuf:"bytes,2,opt,name=old,proto3" json:"old,omitempty"`
	New                  *Entry   `protobuf:"bytes,3,opt,name=new,proto3" json:"new,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Change) Descriptor

func (*Change) Descriptor() ([]byte, []int)

func (*Change) EnsureValid

func (c *Change) EnsureValid() error

EnsureValid ensures that Change's invariants are respected.

func (*Change) GetNew

func (m *Change) GetNew() *Entry

func (*Change) GetOld

func (m *Change) GetOld() *Entry

func (*Change) GetPath

func (m *Change) GetPath() string

func (*Change) ProtoMessage

func (*Change) ProtoMessage()

func (*Change) Reset

func (m *Change) Reset()

func (*Change) String

func (m *Change) String() string

func (*Change) XXX_DiscardUnknown

func (m *Change) XXX_DiscardUnknown()

func (*Change) XXX_Marshal

func (m *Change) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Change) XXX_Merge

func (dst *Change) XXX_Merge(src proto.Message)

func (*Change) XXX_Size

func (m *Change) XXX_Size() int

func (*Change) XXX_Unmarshal

func (m *Change) XXX_Unmarshal(b []byte) error

type Conflict

type Conflict struct {
	AlphaChanges         []*Change `protobuf:"bytes,1,rep,name=alphaChanges,proto3" json:"alphaChanges,omitempty"`
	BetaChanges          []*Change `protobuf:"bytes,2,rep,name=betaChanges,proto3" json:"betaChanges,omitempty"`
	XXX_NoUnkeyedLiteral struct{}  `json:"-"`
	XXX_unrecognized     []byte    `json:"-"`
	XXX_sizecache        int32     `json:"-"`
}

func (*Conflict) Descriptor

func (*Conflict) Descriptor() ([]byte, []int)

func (*Conflict) EnsureValid

func (c *Conflict) EnsureValid() error

EnsureValid ensures that Conflict's invariants are respected.

func (*Conflict) GetAlphaChanges

func (m *Conflict) GetAlphaChanges() []*Change

func (*Conflict) GetBetaChanges

func (m *Conflict) GetBetaChanges() []*Change

func (*Conflict) ProtoMessage

func (*Conflict) ProtoMessage()

func (*Conflict) Reset

func (m *Conflict) Reset()

func (*Conflict) String

func (m *Conflict) String() string

func (*Conflict) XXX_DiscardUnknown

func (m *Conflict) XXX_DiscardUnknown()

func (*Conflict) XXX_Marshal

func (m *Conflict) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Conflict) XXX_Merge

func (dst *Conflict) XXX_Merge(src proto.Message)

func (*Conflict) XXX_Size

func (m *Conflict) XXX_Size() int

func (*Conflict) XXX_Unmarshal

func (m *Conflict) XXX_Unmarshal(b []byte) error

type Entry

type Entry struct {
	// Kind encodes the type of filesystem entry being represented.
	Kind EntryKind `protobuf:"varint,1,opt,name=kind,proto3,enum=sync.EntryKind" json:"kind,omitempty"`
	// Contents represents a directory entry's contents.
	Contents map[string]*Entry `` /* 157-byte string literal not displayed */
	// Digest represents the hash of a file entry's contents.
	Digest []byte `protobuf:"bytes,8,opt,name=digest,proto3" json:"digest,omitempty"`
	// Executable indicates whether or not a file entry is marked as executable.
	Executable bool `protobuf:"varint,9,opt,name=executable,proto3" json:"executable,omitempty"`
	// Target is the symlink target for symlink entries.
	Target               string   `protobuf:"bytes,12,opt,name=target,proto3" json:"target,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Entry represents a filesystem node (e.g. a directory, a file, or a symlink).

func Apply

func Apply(base *Entry, changes []*Change) (*Entry, error)

Apply applies a series of changes to a base entry. It's worth nothing that this function ignores the Old value for changes and that it assumes all changes are valid.

func PropagateExecutability

func PropagateExecutability(ancestor, source, target *Entry) *Entry

PropagateExecutability propagates file executability from the ancestor and source to the target in a recursive fashion. Executability information is only propagated if entry paths, types, and contents match, with source taking precedent over ancestor.

func (*Entry) Copy

func (e *Entry) Copy() *Entry

Copy creates a deep copy of the entry.

func (*Entry) CopyShallow

func (e *Entry) CopyShallow() *Entry

CopyShallow creates a shallow copy of the entry (excluding directory contents, if any).

func (*Entry) Descriptor

func (*Entry) Descriptor() ([]byte, []int)

func (*Entry) EnsureValid

func (e *Entry) EnsureValid() error

EnsureValid ensures that Entry's invariants are respected.

func (*Entry) Equal

func (e *Entry) Equal(other *Entry) bool

Equal determines whether or not another entry is entirely (recursively) equal to this one.

func (*Entry) GetContents

func (m *Entry) GetContents() map[string]*Entry

func (*Entry) GetDigest

func (m *Entry) GetDigest() []byte

func (*Entry) GetExecutable

func (m *Entry) GetExecutable() bool

func (*Entry) GetKind

func (m *Entry) GetKind() EntryKind

func (*Entry) GetTarget

func (m *Entry) GetTarget() string

func (*Entry) ProtoMessage

func (*Entry) ProtoMessage()

func (*Entry) Reset

func (m *Entry) Reset()

func (*Entry) String

func (m *Entry) String() string

func (*Entry) XXX_DiscardUnknown

func (m *Entry) XXX_DiscardUnknown()

func (*Entry) XXX_Marshal

func (m *Entry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Entry) XXX_Merge

func (dst *Entry) XXX_Merge(src proto.Message)

func (*Entry) XXX_Size

func (m *Entry) XXX_Size() int

func (*Entry) XXX_Unmarshal

func (m *Entry) XXX_Unmarshal(b []byte) error

type EntryKind

type EntryKind int32

EntryKind encodes the type of entry represented by an Entry object.

const (
	// EntryKind_Directory represents a directory entry.
	EntryKind_Directory EntryKind = 0
	// EntryKind_File represents a file entry.
	EntryKind_File EntryKind = 1
	// EntryKind_Symlink represents a symlink entry.
	EntryKind_Symlink EntryKind = 2
)

func (EntryKind) EnumDescriptor

func (EntryKind) EnumDescriptor() ([]byte, []int)

func (EntryKind) String

func (x EntryKind) String() string

type IgnoreCache added in v0.6.0

type IgnoreCache map[IgnoreCacheKey]bool

IgnoreCache provides an efficient mechanism to avoid recomputing ignores.

type IgnoreCacheKey added in v0.6.0

type IgnoreCacheKey struct {
	// contains filtered or unexported fields
}

IgnoreCacheKey represents a key in an ignore cache.

type IgnoreVCSMode

type IgnoreVCSMode int32

IgnoreVCSMode specifies the mode for ignoring VCS directories.

const (
	// IgnoreVCSMode_IgnoreVCSDefault represents an unspecified VCS ignore
	// mode. It is not valid for use with Scan. It should be converted to one of
	// the following values based on the desired default behavior.
	IgnoreVCSMode_IgnoreVCSDefault IgnoreVCSMode = 0
	// IgnoreVCSMode_IgnoreVCS indicates that VCS directories should be ignored.
	IgnoreVCSMode_IgnoreVCS IgnoreVCSMode = 1
	// IgnoreVCSMode_PropagateVCS indicates that VCS directories should be
	// propagated.
	IgnoreVCSMode_PropagateVCS IgnoreVCSMode = 2
)

func (IgnoreVCSMode) Description

func (m IgnoreVCSMode) Description() string

Description returns a human-readable description of a VCS ignore mode.

func (IgnoreVCSMode) EnumDescriptor

func (IgnoreVCSMode) EnumDescriptor() ([]byte, []int)

func (IgnoreVCSMode) String

func (x IgnoreVCSMode) String() string

func (IgnoreVCSMode) Supported

func (m IgnoreVCSMode) Supported() bool

Supported indicates whether or not a particular VCS ignore mode is a valid, non-default value.

func (*IgnoreVCSMode) UnmarshalText

func (m *IgnoreVCSMode) UnmarshalText(textBytes []byte) error

UnmarshalText implements the text unmarshalling interface used when loading from TOML files.

type Problem

type Problem struct {
	Path                 string   `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
	Error                string   `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Problem) Descriptor

func (*Problem) Descriptor() ([]byte, []int)

func (*Problem) EnsureValid

func (p *Problem) EnsureValid() error

EnsureValid ensures that Problem's invariants are respected.

func (*Problem) GetError

func (m *Problem) GetError() string

func (*Problem) GetPath

func (m *Problem) GetPath() string

func (*Problem) ProtoMessage

func (*Problem) ProtoMessage()

func (*Problem) Reset

func (m *Problem) Reset()

func (*Problem) String

func (m *Problem) String() string

func (*Problem) XXX_DiscardUnknown

func (m *Problem) XXX_DiscardUnknown()

func (*Problem) XXX_Marshal

func (m *Problem) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Problem) XXX_Merge

func (dst *Problem) XXX_Merge(src proto.Message)

func (*Problem) XXX_Size

func (m *Problem) XXX_Size() int

func (*Problem) XXX_Unmarshal

func (m *Problem) XXX_Unmarshal(b []byte) error

type Provider

type Provider interface {
	// Provide returns a filesystem path to a file containing the contents for
	// the path given as the first argument with the digest specified by the
	// second argument.
	Provide(path string, digest []byte) (string, error)
}

Provider defines the interface that higher-level logic can use to provide files to transition algorithms.

type ReverseLookupMap added in v0.5.0

type ReverseLookupMap struct {
	// contains filtered or unexported fields
}

ReverseLookupMap provides facilities for doing reverse lookups to avoid expensive staging operations in the case of renames and copies.

func (*ReverseLookupMap) Lookup added in v0.5.0

func (m *ReverseLookupMap) Lookup(digest []byte) (string, bool)

Lookup attempts a lookup in the map.

type SymlinkMode

type SymlinkMode int32

SymlinkMode specifies the mode for handling the propagation of symlinks.

const (
	// SymlinkMode_SymlinkDefault represents an unspecified symlink mode. It is
	// not valid for use with Scan or Transition. It should be converted to one
	// of the following values based on the desired default behavior.
	SymlinkMode_SymlinkDefault SymlinkMode = 0
	// SymlinkMode_SymlinkIgnore specifies that all symlinks should be ignored.
	SymlinkMode_SymlinkIgnore SymlinkMode = 1
	// SymlinkMode_SymlinkPortable specifies that only portable symlinks should
	// be synchronized. If a symlink is found during a scan operation that it is
	// not portable, it halts the scan and synchronization. The reason for this
	// is that it can't simply be ignored/unignored as desired without breaking
	// the three-way merge.
	SymlinkMode_SymlinkPortable SymlinkMode = 2
	// SymlinkMode_SymlinkPOSIXRaw specifies that symlinks should be propagated
	// in their raw form. It is only valid on POSIX systems and only makes sense
	// in the context of POSIX-to-POSIX synchronization.
	SymlinkMode_SymlinkPOSIXRaw SymlinkMode = 3
)

func (SymlinkMode) Description

func (m SymlinkMode) Description() string

Description returns a human-readable description of a symlink mode.

func (SymlinkMode) EnumDescriptor

func (SymlinkMode) EnumDescriptor() ([]byte, []int)

func (SymlinkMode) String

func (x SymlinkMode) String() string

func (SymlinkMode) Supported

func (m SymlinkMode) Supported() bool

Supported indicates whether or not a particular symlink mode is a valid, non-default value.

func (*SymlinkMode) UnmarshalText

func (m *SymlinkMode) UnmarshalText(textBytes []byte) error

UnmarshalText implements the text unmarshalling interface used when loading from TOML files.

Jump to

Keyboard shortcuts

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