Documentation
¶
Index ¶
- Constants
- func FileKey(abs string) string
- func GlobalRoot() (string, error)
- func HashBytes(b []byte) string
- func NormalizePath(abs string) string
- type Code
- type Error
- type Index
- type Kind
- type MoveResult
- type PrunePolicy
- type PruneReport
- type RemovedVersion
- type RestoreResult
- type SaveOptions
- type SaveResult
- type Status
- type Store
- func (s *Store) Content(file string, n int) ([]byte, error)
- func (s *Store) Files() ([]*Index, []Unreadable, error)
- func (s *Store) History(file string) (*Index, error)
- func (s *Store) Move(from, to string) (MoveResult, error)
- func (s *Store) Orphans() ([]*Index, error)
- func (s *Store) Prune(p PrunePolicy) (PruneReport, error)
- func (s *Store) Remove(file string) error
- func (s *Store) RemoveHistory(ix *Index) error
- func (s *Store) Restore(file string, n int, o SaveOptions) (RestoreResult, error)
- func (s *Store) Save(file string, o SaveOptions) (SaveResult, error)
- func (s *Store) Status(file string) (Status, error)
- type Unreadable
- type Version
Constants ¶
const OopsDir = ".oops"
OopsDir is the name of a local store directory.
Variables ¶
This section is empty.
Functions ¶
func GlobalRoot ¶ added in v0.4.0
GlobalRoot is the store in the user's home directory.
func NormalizePath ¶ added in v0.4.0
NormalizePath makes one spelling per file: forward slashes, and on Windows (case-insensitive file system) the whole path in lower case.
Types ¶
type Code ¶ added in v0.4.0
type Code string
Code classifies an error so a caller can react without parsing text.
type Index ¶ added in v0.4.0
type Index struct {
Format int `json:"format"`
Path string `json:"path"`
Next int `json:"next"`
Versions []Version `json:"versions"`
}
Index is a file's version list.
type Kind ¶ added in v0.4.0
type Kind string
Kind tells how a version was made; retention treats them differently.
type MoveResult ¶ added in v0.4.0
type MoveResult struct {
From string `json:"from"`
To string `json:"to"`
MovedFile bool `json:"movedFile"`
}
MoveResult reports a move. MovedFile is false when only the history moved.
type PrunePolicy ¶ added in v0.4.0
PrunePolicy limits what a store keeps. A zero field is no limit.
type PruneReport ¶ added in v0.4.0
type PruneReport struct {
DryRun bool `json:"dryRun"`
Removed []RemovedVersion `json:"removed"`
FreedBytes int64 `json:"freedBytes"`
TotalBytes int64 `json:"totalBytes"`
OverCapBytes int64 `json:"overCapBytes"`
Unreadable []Unreadable `json:"unreadable"`
}
PruneReport is the outcome of a prune.
type RemovedVersion ¶ added in v0.4.0
type RemovedVersion struct {
Path string `json:"path"`
N int `json:"n"`
Reason string `json:"reason"`
}
RemovedVersion names a version prune removed (or would remove).
type RestoreResult ¶ added in v0.4.0
type RestoreResult struct {
Path string `json:"path"`
Restored int `json:"restored"`
SavedBefore *Version `json:"savedBefore"`
}
RestoreResult reports a restore. SavedBefore is the version that kept the file's unsaved content, nil when there was nothing to keep.
type SaveOptions ¶ added in v0.4.0
SaveOptions describes the version a save creates.
type SaveResult ¶ added in v0.4.0
type SaveResult struct {
Saved bool `json:"saved"`
Reason string `json:"reason,omitempty"`
Path string `json:"path"`
Version Version `json:"version"`
}
SaveResult reports a save. Saved is false when the content equals the latest version.
type Status ¶ added in v0.4.0
type Status struct {
Path string `json:"path"`
Exists bool `json:"exists"`
Latest int `json:"latest"`
Current int `json:"current"`
Changed bool `json:"changed"`
}
Status compares a file on disk with its history.
type Store ¶
type Store struct {
Root string
LockTimeout time.Duration
// contains filtered or unexported fields
}
Store is a directory holding the version history of any number of files.
func Open ¶ added in v0.4.0
Open returns the store rooted at root. Nothing is created until a version is saved.
func OpenLocal ¶ added in v0.4.0
OpenLocal returns the store kept in base/.oops. Files under base are recorded by their path relative to base, so renaming or moving the folder keeps its history.
func (*Store) Files ¶ added in v0.4.0
func (s *Store) Files() ([]*Index, []Unreadable, error)
Files lists every history in the store, and separately the ones whose index cannot be read.
func (*Store) Move ¶ added in v0.4.0
func (s *Store) Move(from, to string) (MoveResult, error)
Move carries a file's history to a new path, moving the file too when it is still at the old path. Both histories are locked for the whole move and the history is carried file by file (content is linked, or copied where a link is not possible), never by renaming its directory — so no lock is released early, and at every point one complete index describes the file: the new one is written before the old one is cleared, and a failure clears the new one and leaves the old history as it was.
func (*Store) Orphans ¶ added in v0.4.0
Orphans lists histories whose file no longer exists on disk.
func (*Store) Prune ¶ added in v0.4.0
func (s *Store) Prune(p PrunePolicy) (PruneReport, error)
Prune applies the retention policy to the whole store. Only auto versions are removed.
func (*Store) RemoveHistory ¶ added in v0.4.0
RemoveHistory deletes the history an index describes.
func (*Store) Restore ¶ added in v0.4.0
func (s *Store) Restore(file string, n int, o SaveOptions) (RestoreResult, error)
Restore writes version n back to the file. Content on disk that matches no version is first kept as a saved (manual) version, so a restore never loses work and prune never removes that copy.
func (*Store) Save ¶
func (s *Store) Save(file string, o SaveOptions) (SaveResult, error)
Save records the file's current content as a new version. Saving content equal to the latest version is a successful no-op (Saved=false, Reason "unchanged").
type Unreadable ¶ added in v0.4.0
Unreadable names a history whose index could not be read.
type Version ¶ added in v0.4.0
type Version struct {
N int `json:"n"`
Hash string `json:"hash"`
Size int64 `json:"size"`
Time time.Time `json:"time"`
Kind Kind `json:"kind"`
Actor string `json:"actor,omitempty"`
Label string `json:"label,omitempty"`
Meta map[string]string `json:"meta,omitempty"`
}
Version is one saved state of a file.