sync

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncPriority = "Priority"
	SyncStandard = "Standard"
)
View Source
const (
	DefaultIgnoreTimeout = time.Second
)

Variables

View Source
var (
	ErrSyncAlreadyRunning = errors.New("sync already running")
)

Functions

func ConflictFileExists added in v0.7.0

func ConflictFileExists(basePath string) bool

ConflictFileExists checks the filesystem to see if any .conflict file (including rotated versions) exists for the given base path.

func GetUnmarkedPath added in v0.7.0

func GetUnmarkedPath(path string) string

GetUnmarkedPath strips all known markers and rotation timestamps from a path string to reveal the original, unmarked path.

func IsConflictPath added in v0.7.0

func IsConflictPath(path string) bool

IsConflict checks if a path string is specifically marked as a conflict.

func IsLegacyMarkedPath added in v0.7.0

func IsLegacyMarkedPath(path string) bool

func IsMarkedPath added in v0.7.0

func IsMarkedPath(path string) bool

IsMarkedPath checks if a given path string contains any known marker, including rotated (timestamped) variants.

func IsRejectedPath added in v0.7.0

func IsRejectedPath(path string) bool

IsRejected checks if a path string is specifically marked as rejected.

func RejectedFileExists added in v0.7.0

func RejectedFileExists(basePath string) bool

RejectedFileExists checks the filesystem to see if any .rejected file (including rotated versions) exists for the given base path.

func RemoveMarker added in v0.7.0

func RemoveMarker(path string) (string, error)

RemoveMarker renames a marked file to its original, unmarked name. It returns the original path.

func SetMarker added in v0.7.0

func SetMarker(path string, mtype MarkerType) (string, error)

SetMarker applies a marker to a file at a given path. If a file with the same marker already exists, it is "rotated" by renaming it with its modification timestamp before the new file is marked. It returns the new path of the marked file.

Types

type BatchCleanups

type BatchCleanups = map[SyncPath]struct{}

BatchCleanups represents a set of paths that require local cleanup (e.g., removing tombstones).

type BatchConflict

type BatchConflict = map[SyncPath]*SyncOperation

BatchConflict represents a collection of sync operations where conflicts were detected.

type BatchIgnored

type BatchIgnored = map[SyncPath]struct{}

BatchIgnored represents a set of paths that were ignored.

type BatchLocalDelete

type BatchLocalDelete = map[SyncPath]*SyncOperation

BatchLocalDelete represents a collection of sync operations for items deleted locally.

type BatchLocalWrite

type BatchLocalWrite = map[SyncPath]*SyncOperation

BatchLocalWrite represents a collection of sync operations for items created or updated locally.

type BatchRemoteDelete

type BatchRemoteDelete = map[SyncPath]*SyncOperation

BatchRemoteDelete represents a collection of sync operations for items deleted remotely.

type BatchRemoteWrite

type BatchRemoteWrite = map[SyncPath]*SyncOperation

BatchRemoteWrite represents a collection of sync operations for items created or updated remotely.

type BatchUnchanged

type BatchUnchanged = map[SyncPath]struct{}

BatchUnchanged represents a set of paths that were compared and found to be unchanged.

type ConflictState added in v0.7.0

type ConflictState string

ConflictState represents the condition of a file

const (
	ConflictStateNone       ConflictState = "none"
	ConflictStateConflicted ConflictState = "conflicted"
	ConflictStateRejected   ConflictState = "rejected"
)

type FileContent

type FileContent struct {
	FileMetadata
	Content []byte
}

func NewFileContent

func NewFileContent(path string) (*FileContent, error)

type FileMetadata

type FileMetadata struct {
	Path         SyncPath
	Size         int64
	ETag         string
	Version      string
	LastModified time.Time
}

type FileWatcher

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

func NewFileWatcher

func NewFileWatcher(watchDir string) *FileWatcher

func (*FileWatcher) Events

func (fw *FileWatcher) Events() <-chan notify.EventInfo

func (*FileWatcher) FilterPaths added in v0.7.0

func (fw *FileWatcher) FilterPaths(callback FilterCallback)

FilterPaths sets a callback function to filter out raw events before debouncing The callback should return true if the event should be ignored

func (*FileWatcher) IgnoreOnce added in v0.7.0

func (fw *FileWatcher) IgnoreOnce(path string)

IgnoreOnce adds a path to be ignored on the next write event with default timeout

func (*FileWatcher) IgnoreOnceWithTimeout added in v0.7.0

func (fw *FileWatcher) IgnoreOnceWithTimeout(path string, timeout time.Duration)

IgnoreOnceWithTimeout adds a path to be ignored on the next write event with custom timeout

func (*FileWatcher) SetCleanupInterval added in v0.7.0

func (fw *FileWatcher) SetCleanupInterval(interval time.Duration)

func (*FileWatcher) SetDebounceTimeout added in v0.7.0

func (fw *FileWatcher) SetDebounceTimeout(timeout time.Duration)

SetDebounceTimeout sets the debounce timeout for events

func (*FileWatcher) Start

func (fw *FileWatcher) Start(ctx context.Context) error

func (*FileWatcher) Stop

func (fw *FileWatcher) Stop()

type FilterCallback added in v0.7.0

type FilterCallback func(path string) bool

FilterCallback is a function that returns true if the event should be filtered

type MarkerType added in v0.7.0

type MarkerType string

MarkerType defines the type of marker to be applied to a file. We use simple dot-suffixes for command-line friendliness (no special chars).

const (
	// LegacyRejected marks a file as rejected.
	LegacyRejected MarkerType = ".syftrejected"
	// LegacyConflict marks a file as having a conflict.
	LegacyConflict MarkerType = ".syftconflict"

	// Rejected marks a file as rejected.
	Rejected MarkerType = ".rejected"
	// Conflict marks a file as having a conflict.
	Conflict MarkerType = ".conflict"
)

func GetMarkers added in v0.7.0

func GetMarkers(path string) []MarkerType

GetMarkers finds all known markers in a given path string.

type OpType

type OpType string
const (
	OpWriteRemote  OpType = "WriteRemote"
	OpWriteLocal   OpType = "WriteLocal"
	OpDeleteRemote OpType = "DeleteRemote"
	OpDeleteLocal  OpType = "DeleteLocal"
	OpConflict     OpType = "Conflict"
	OpError        OpType = "Error"
	OpSkipped      OpType = "Skipped"
)

type PathStatus

type PathStatus struct {
	SyncState     SyncState
	ConflictState ConflictState
	Progress      float64
	Error         error
	ErrorCount    int
	LastUpdated   time.Time
}

PathStatus represents the complete status of a file

func (*PathStatus) String added in v0.7.0

func (s *PathStatus) String() string

type ReconcileOperations

type ReconcileOperations struct {
	LocalWrites    BatchLocalWrite
	RemoteWrites   BatchRemoteWrite
	LocalDeletes   BatchLocalDelete
	RemoteDeletes  BatchRemoteDelete
	Conflicts      BatchConflict
	UnchangedPaths BatchUnchanged
	Cleanups       BatchCleanups
	Ignored        BatchIgnored
	Total          int
}

ReconcileOperations aggregates the results of a sync reconciliation process, categorizing operations based on their type and origin.

func NewReconcileOperations

func NewReconcileOperations() *ReconcileOperations

NewReconcileOperations initializes and returns an empty ReconcileOperations struct.

func (*ReconcileOperations) HasChanges

func (r *ReconcileOperations) HasChanges() bool

HasChanges returns true if there are any pending write, delete, conflict, or cleanup operations resulting from the reconciliation.

type SyncEngine

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

func NewSyncEngine

func NewSyncEngine(
	workspace *workspace.Workspace,
	sdk *syftsdk.SyftSDK,
	ignore *SyncIgnoreList,
	priority *SyncPriorityList,
) (*SyncEngine, error)

func (*SyncEngine) RunSync

func (se *SyncEngine) RunSync(ctx context.Context) error

RunSync performs a full sync of the local and remote states

func (*SyncEngine) Start

func (se *SyncEngine) Start(ctx context.Context) error

func (*SyncEngine) Stop

func (se *SyncEngine) Stop() error

type SyncIgnoreList

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

func NewSyncIgnoreList

func NewSyncIgnoreList(baseDir string) *SyncIgnoreList

func (*SyncIgnoreList) Load

func (s *SyncIgnoreList) Load()

func (*SyncIgnoreList) ShouldIgnore

func (s *SyncIgnoreList) ShouldIgnore(path string) bool

type SyncJournal

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

SyncJournal manages the persistent state of synced files using SQLite.

func NewSyncJournal

func NewSyncJournal(dbPath string) (*SyncJournal, error)

NewSyncJournal creates or opens a SyncJournal backed by an SQLite database.

func (*SyncJournal) Close

func (s *SyncJournal) Close() error

Close closes the underlying database connection.

func (*SyncJournal) ContentsChanged

func (s *SyncJournal) ContentsChanged(path SyncPath, etag string) (bool, error)

func (*SyncJournal) Count

func (s *SyncJournal) Count() (int, error)

Count returns the number of entries in the journal.

func (*SyncJournal) Delete

func (s *SyncJournal) Delete(path SyncPath) error

Delete removes an entry from the journal by its key (path).

func (*SyncJournal) Destroy

func (s *SyncJournal) Destroy() error

in rare cases when we want to destroy the journal & would want to start afresh

func (*SyncJournal) Get

func (s *SyncJournal) Get(path SyncPath) (*FileMetadata, error)

Get retrieves the metadata for a specific path.

func (*SyncJournal) GetPaths

func (s *SyncJournal) GetPaths() ([]SyncPath, error)

GetPaths retrieves all paths known to the journal.

func (*SyncJournal) GetState

func (s *SyncJournal) GetState() (map[SyncPath]*FileMetadata, error)

GetState retrieves the entire state map from the journal.

func (*SyncJournal) Open

func (s *SyncJournal) Open() error

Open the sync journal and the underlying database

func (*SyncJournal) Set

func (s *SyncJournal) Set(state *FileMetadata) error

Set inserts or updates the metadata for a specific path using named parameters.

type SyncLocalState

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

func NewSyncLocalState

func NewSyncLocalState(rootDir string) *SyncLocalState

func (*SyncLocalState) Scan

func (s *SyncLocalState) Scan() (map[SyncPath]*FileMetadata, error)

type SyncManager

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

func NewManager

func NewManager(workspace *workspace.Workspace, sdk *syftsdk.SyftSDK) (*SyncManager, error)

func (*SyncManager) Start

func (m *SyncManager) Start(ctx context.Context) error

func (*SyncManager) Stop

func (m *SyncManager) Stop() error

type SyncOperation

type SyncOperation struct {
	Type       OpType
	RelPath    SyncPath
	Local      *FileMetadata
	Remote     *FileMetadata
	LastSynced *FileMetadata
}

type SyncPath added in v0.7.0

type SyncPath string // common relative path on the client and server

func (SyncPath) String added in v0.7.0

func (p SyncPath) String() string

type SyncPriorityList

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

func NewSyncPriorityList

func NewSyncPriorityList(baseDir string) *SyncPriorityList

func (*SyncPriorityList) ShouldPrioritize

func (s *SyncPriorityList) ShouldPrioritize(path string) bool

type SyncState added in v0.7.0

type SyncState string

SyncState represents the state of a sync operation

const (
	SyncStatePending   SyncState = "pending"
	SyncStateSyncing   SyncState = "syncing"
	SyncStateCompleted SyncState = "completed"
	SyncStateError     SyncState = "error"
)

type SyncStatus

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

SyncStatus manages the status of file synchronization operations

func NewSyncStatus

func NewSyncStatus() *SyncStatus

func (*SyncStatus) Cleanup added in v0.7.0

func (s *SyncStatus) Cleanup(maxAge time.Duration)

Cleanup removes completed files older than the specified duration

func (*SyncStatus) Close added in v0.7.0

func (s *SyncStatus) Close()

func (*SyncStatus) GetAllStatus added in v0.7.0

func (s *SyncStatus) GetAllStatus() map[SyncPath]*PathStatus

GetAllStatus returns a copy of all file statuses

func (*SyncStatus) GetConflictedFileCount added in v0.7.0

func (s *SyncStatus) GetConflictedFileCount() int

GetConflictedFileCount returns the number of conflicted files

func (*SyncStatus) GetConflictedFiles added in v0.7.0

func (s *SyncStatus) GetConflictedFiles() map[SyncPath]*PathStatus

GetConflictedFiles returns a map of all conflicted files

func (*SyncStatus) GetErrorCount added in v0.7.0

func (s *SyncStatus) GetErrorCount(path SyncPath) int

func (*SyncStatus) GetRejectedFileCount added in v0.7.0

func (s *SyncStatus) GetRejectedFileCount() int

GetRejectedFileCount returns the number of rejected files

func (*SyncStatus) GetRejectedFiles added in v0.7.0

func (s *SyncStatus) GetRejectedFiles() map[SyncPath]*PathStatus

GetRejectedFiles returns a map of all rejected files

func (*SyncStatus) GetStatus added in v0.7.0

func (s *SyncStatus) GetStatus(path SyncPath) (*PathStatus, bool)

GetStatus returns the status of a specific file

func (*SyncStatus) GetSyncingFileCount added in v0.7.0

func (s *SyncStatus) GetSyncingFileCount() int

GetSyncingFileCount returns the number of files currently syncing

func (*SyncStatus) SetCompleted

func (s *SyncStatus) SetCompleted(path SyncPath)

SetCompleted sets a file to completed state, preserving file state and removing only clean files

func (*SyncStatus) SetCompletedAndRemove added in v0.7.0

func (s *SyncStatus) SetCompletedAndRemove(path SyncPath)

SetCompletedAndRemove explicitly clears a file to clean state and removes it from tracking

func (*SyncStatus) SetConflicted added in v0.7.0

func (s *SyncStatus) SetConflicted(path SyncPath)

SetConflicted marks a file as conflicted

func (*SyncStatus) SetError

func (s *SyncStatus) SetError(path SyncPath, err error)

SetError sets a file to error state

func (*SyncStatus) SetProgress

func (s *SyncStatus) SetProgress(path SyncPath, progress float64)

SetProgress updates the progress of a syncing file

func (*SyncStatus) SetRejected added in v0.7.0

func (s *SyncStatus) SetRejected(path SyncPath)

SetRejected marks a file as rejected

func (*SyncStatus) SetSyncing

func (s *SyncStatus) SetSyncing(path SyncPath)

SetSyncing sets a file to syncing state, preserving conflicted/rejected file state

func (*SyncStatus) Subscribe added in v0.7.0

func (s *SyncStatus) Subscribe() <-chan *SyncStatusEvent

Subscribe returns a channel for receiving sync status events

func (*SyncStatus) Unsubscribe added in v0.7.0

func (s *SyncStatus) Unsubscribe(ch <-chan *SyncStatusEvent)

Unsubscribe removes a subscription channel

type SyncStatusEvent

type SyncStatusEvent struct {
	Path   SyncPath
	Status *PathStatus
}

SyncStatusEvent represents a status change event for broadcasting

Jump to

Keyboard shortcuts

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