Documentation
¶
Index ¶
- func ExcludeHash(patterns []string) string
- func IsUnderExcludedDir(relPath string, excludedDirs []string) bool
- func ParseExcludeFile(path string) ([]string, error)
- type ChangeType
- type ExcludeMatcher
- type FileChange
- type FileMeta
- type FileType
- type IncrementalSource
- type Source
- type SourceInfo
- type SourceSize
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExcludeHash ¶ added in v1.18.0
ExcludeHash is the canonical fingerprint of a set of exclude patterns, as recorded on a snapshot.
It is repository format, not a convenience. A backup writes it, and the next backup compares its own against the previous snapshot's to decide whether the exclude set changed: when it did, the incremental change feed cannot be trusted — files newly excluded must be dropped and newly included files found — so the engine falls back to a full rescan. Two callers computing it differently therefore do not merely disagree about a string; one of them silently skips that rescan, or forces one on every run.
The patterns are joined in the order given, so this is a hash of the exclude *list*, not of the set: reordering the same patterns reads as a change. That is deliberate and cheap — a spurious full rescan is safe, a skipped one is not.
func IsUnderExcludedDir ¶ added in v1.18.0
IsUnderExcludedDir reports whether true if relPath falls under any of the excluded directory prefixes. Each entry in excludedDirs must end with '/'.
func ParseExcludeFile ¶
ParseExcludeFile reads patterns from a file (one per line) and returns them. Comment lines (#) and blank lines are preserved for NewExcludeMatcher to handle.
Types ¶
type ChangeType ¶
type ChangeType string
ChangeType describes the kind of change reported by an IncrementalSource.
const ( ChangeUpsert ChangeType = "upsert" ChangeDelete ChangeType = "delete" )
type ExcludeMatcher ¶
type ExcludeMatcher struct {
// contains filtered or unexported fields
}
ExcludeMatcher evaluates gitignore-style exclude patterns against relative file paths. Patterns are evaluated in order; the last matching rule wins.
func NewExcludeMatcher ¶
func NewExcludeMatcher(patterns []string) *ExcludeMatcher
NewExcludeMatcher compiles the given pattern strings into a matcher. Supported syntax (subset of gitignore):
- Blank lines and lines starting with '#' are ignored.
- A trailing '/' matches only directories.
- A leading '!' negates the pattern (re-includes a previously excluded path).
- '*' matches anything except '/'.
- '**' matches zero or more path segments.
- Patterns without '/' match against the file/dir name in any directory.
- Patterns with '/' are anchored to the root of the walk.
The glob syntax itself is internal/pathmatch's: path.Match per segment, plus '**' for zero or more segments. Only the gitignore layer — negation, directory-only, anchoring, last-rule-wins — lives here.
func (*ExcludeMatcher) Empty ¶
func (m *ExcludeMatcher) Empty() bool
Empty returns true if the matcher has no rules.
type FileChange ¶
type FileChange struct {
Type ChangeType
Meta FileMeta
}
FileChange pairs a change type with file metadata. For deletions only Meta.FileID is required.
func TopoSortFolderChanges ¶ added in v1.18.0
func TopoSortFolderChanges(changes []FileChange) []FileChange
TopoSortFolderChanges orders folder upsert changes so that every parent appears before its children, using the raw source parent IDs in Meta.Parents.
Incremental sources need this because Source implementations must emit parents before children (see Source.Walk), but a change feed reports entries in modification order, which carries no such guarantee.
Changes whose parent is not itself in the batch keep their relative order; only entries that constrain each other are reordered.
type FileMeta ¶ added in v1.18.0
type FileMeta struct {
Version int `json:"version"`
FileID string `json:"fileId"` // Google Drive file ID (HAMT key)
Name string `json:"name"`
Type FileType `json:"type"` // "file" or "folder"
// Parents holds raw source FileIDs — the same values used as HAMT keys —
// not "filemeta/<sha256>" refs. Resolving one therefore means a lookup by
// key, not a Get. See internal/engine/backup_scan.go and restore.go.
Parents []string `json:"parents"`
Paths []string `json:"paths,omitempty"`
ContentHash string `json:"content_hash"` // SHA256 of the file content
ContentRef string `json:"content_ref,omitempty"` // HMAC(dedupKey, ContentHash) for secure backend lookup
Size int64 `json:"size"`
Mtime int64 `json:"mtime"` // Unix timestamp
Owner string `json:"owner"`
Extra map[string]interface{} `json:"extra,omitempty"`
Mode uint32 `json:"mode,omitempty"` // POSIX permission bits (st_mode & 0xFFF)
Uid uint32 `json:"uid,omitempty"` // POSIX user ID
Gid uint32 `json:"gid,omitempty"` // POSIX group ID
Btime int64 `json:"btime,omitempty"` // birth/creation time, Unix seconds; 0 = not available
Flags uint32 `json:"flags,omitempty"` // per-file flags (chflags / FS_IOC_GETFLAGS)
Xattrs map[string][]byte `json:"xattrs,omitempty"` // extended attributes: name → raw bytes
}
FileMeta represents immutable file metadata Object key: filemeta/<sha256>
type FileType ¶ added in v1.18.0
type FileType string
FileType defines the generic type of the file (e.g. generic file, folder, symlink)
type IncrementalSource ¶
type IncrementalSource interface {
Source
// GetStartPageToken returns the token representing the current head of
// the change stream. Call this before a full Walk to capture the baseline.
GetStartPageToken() (string, error)
// WalkChanges emits only the entries that changed since token.
// It returns the new token to persist for the next run.
WalkChanges(ctx context.Context, token string, callback func(FileChange) error) (newToken string, err error)
}
IncrementalSource token stored in the snapshot. On the first run (empty token) the engine falls back to the full Walk; on subsequent runs only changed entries are emitted.
type Source ¶
type Source interface {
Walk(ctx context.Context, callback func(FileMeta) error) error
GetFileStream(fileID string) (io.ReadCloser, error)
Info() SourceInfo
Size(ctx context.Context) (*SourceSize, error)
}
Source is the interface for a backup data source (local filesystem, Google Drive, OneDrive, etc.). Implementations MUST ensure that parent folders are visited before their children during Walk.
type SourceInfo ¶ added in v1.18.0
type SourceInfo struct {
Type string `json:"type"` // e.g. "gdrive", "local"
Account string `json:"account,omitempty"` // friendly account/host label for display
Path string `json:"path,omitempty"` // display path within the source container
Identity string `json:"identity,omitempty"` // stable container identity for lineage matching
PathID string `json:"path_id,omitempty"` // stable selected-root identity within container
DriveName string `json:"drive_name,omitempty"` // human-readable container label (e.g. "My Drive")
FsType string `json:"fs_type,omitempty"` // source filesystem type (e.g. "apfs", "ext4", "sftp")
}
SourceInfo describes the origin of a backup snapshot. It is stored as a first-class field on the snapshot so that forget policies can group by source identity (Type + Account + Path).
type SourceSize ¶
SourceSize holds the total size of a source.