Documentation
¶
Overview ¶
Package journal makes every write hopsesh does undoable. Before a file is created, replaced, appended to or moved, the journal records how to reverse it (and keeps a copy of what is replaced), on disk, so an interrupted move can still be undone.
Index ¶
- Constants
- Variables
- func Dir(stateDir string) string
- type Entry
- type Journal
- func (j *Journal) AddKey(k agent.SessionKey)
- func (j *Journal) AddRemote(machine, id string) error
- func (j *Journal) Adopt(machine, p string) error
- func (j *Journal) Append(fsys host.FS, machine, p string, b []byte, o agent.AppendOptions) error
- func (j *Journal) Changed(fsFor func(machine string) (host.FS, error)) error
- func (j *Journal) Forget(machine string) error
- func (j *Journal) Place(machine, staged, dst string, perm fs.FileMode) error
- func (j *Journal) Rename(fsys host.FS, machine, from, to string) error
- func (j *Journal) Seal(fsFor func(machine string) (host.FS, error)) error
- func (j *Journal) SetAside(machine, p string) error
- func (j *Journal) Undo(fsFor func(machine string) (host.FS, error), force bool) error
- func (j *Journal) WriteFile(fsys host.FS, machine, p string, b []byte, perm fs.FileMode) error
- type Op
- type Remote
- type State
Constants ¶
const ( KindMove = "move" // a session brought here in its own agent KindContinue = "continue" // a session continued in another agent KindPush = "push" // a session sent to another machine (its mark and lineage here) KindMark = "mark" // a mark owed to a copy left behind )
Kinds of operations.
Variables ¶
var ErrChanged = errors.New("changed since")
ErrChanged means a file the operation wrote changed since: undoing it would lose that later work.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Op Op `json:"op"`
Machine string `json:"machine"`
Path string `json:"path"`
From string `json:"from,omitempty"` // OpRename
Size int64 `json:"size,omitempty"` // OpAppend: size before
Len int64 `json:"len,omitempty"` // OpAppend: bytes appended
Sum string `json:"sum,omitempty"` // OpAppend: their SHA-256
Mtime time.Time `json:"mtime,omitempty"` // OpAppend: time before
Backup string `json:"backup,omitempty"` // OpReplace: copy of the old file
KeepMtime bool `json:"keepMtime,omitempty"`
Created bool `json:"created,omitempty"` // OpAppend: the append created the file
// OpAppend: lines written later do not build on these bytes (AppendOptions.Standalone).
Standalone bool `json:"standalone,omitempty"`
}
Entry is one journaled write.
type Journal ¶
type Journal struct {
ID string `json:"id"`
Kind string `json:"kind"` // what kind of operation (Kind*)
Title string `json:"title"`
Time time.Time `json:"time"`
Keys []agent.SessionKey `json:"keys"` // the sessions it created or changed
Entries []Entry `json:"entries"`
Undone bool `json:"undone,omitempty"`
// Remote are journals of the same operation kept by hopsesh on other machines (a push):
// undoing this one undoes them too.
Remote []Remote `json:"remote,omitempty"`
// After is the state the operation left each file it created or replaced in (Seal), so
// undo can tell when one was used afterwards and refuse to lose that work.
After []State `json:"after,omitempty"`
// contains filtered or unexported fields
}
Journal is the undo record of one operation (a move, a continuation, a mark).
func (*Journal) AddKey ¶
func (j *Journal) AddKey(k agent.SessionKey)
AddKey records a session the journal concerns.
func (*Journal) Adopt ¶
Adopt records a file another program just created for this operation (an agent's own importer), so undo removes it.
func (*Journal) Append ¶
Append adds to a file, remembering where and what, so undo can take out exactly these bytes, even from between lines written later when they are Standalone.
func (*Journal) Changed ¶
Changed reports the first file that changed since the operation (ErrChanged with what changed), or nil: one it created or replaced, or one it appended to (not Standalone) that has more after its bytes. A file that is gone, or a machine fsFor cannot reach, does not count.
func (*Journal) Forget ¶
Forget drops the entries for a machine whose own hopsesh journals those writes (the sender of a push replays and journals them there).
func (*Journal) Place ¶
Place installs a staged local file at dst on this machine (moving, not copying, when both are on one volume). An existing dst is kept in the journal.
func (*Journal) Seal ¶
Seal records the state the operation left each file it created or replaced in. Files on machines fsFor cannot reach are left out (their undo is not checked).
func (*Journal) Undo ¶
Undo reverses a journal's entries, newest first. fsFor returns the filesystem of a machine by name (an error when it cannot be reached; such entries are reported). Unless force, it refuses (ErrChanged) when a file the operation wrote changed since: undoing would lose that later work.