Documentation
¶
Overview ¶
Package live holds the Directory the service is serving: the document, its Trash and the Editor's settings as last saved, the tree derived from them, and the one step Undo can return to.
It is the only place those change. A write is a function from the current Snapshot to the next store.State; a Copy serialises writes, saves each through its Writer, and swaps the result in only once that succeeds, so a failed save leaves the served Directory matching the disk. Readers take a Snapshot and hold no lock: nothing a Snapshot points at is ever mutated, only replaced.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnbuildable = errors.New("document does not build a tree")
ErrUnbuildable means a document's Households do not form a tree, so it cannot be served. A Copy never writes such a document.
Functions ¶
This section is empty.
Types ¶
type Copy ¶
type Copy struct {
// contains filtered or unexported fields
}
Copy is the Directory being served. Build one with New.
func New ¶
New serves initial. A missing Trash is an empty one and missing settings are an untitled Directory, as they are for a missing file.
func (*Copy) Undo ¶
Undo returns to the state before the latest save, if token names that save. A token that is empty, was never issued, or was retired by a newer save is not an error: Undo reports false and changes nothing.
Undo is exact — it does not purge the Trash it restores — and it is one step: afterwards there is nothing to undo, so Undo is never a toggle. It returns the Snapshot it leaves served, so a caller checking what still exists sees the state the Undo produced rather than a later one.
func (*Copy) Update ¶
Update makes one change. build receives the current Snapshot and returns the next State; it runs while other writers wait, so it must do no I/O and must not call back into c.
A field build leaves nil is left as served, and handing back the Snapshot's effective Trash means the Trash did not change. When nothing changed, Update writes nothing, issues no Undo and leaves the previous Undo standing. Otherwise it purges the Trash if the Trash changed, builds the tree, writes, and only then serves the result and records it as the one step Undo can reverse.
An error from build is returned as it is, so a caller can carry its own refusal out; nothing is written. Any error leaves the served state and its Undo untouched.
type Saved ¶
type Saved struct {
// Snapshot is what is served after the call, whether or not it saved.
Snapshot Snapshot
// Changed is false when the build handed back what was already served:
// nothing was written and no Undo was issued.
Changed bool
// Undo is the token of this save's Undo, or empty when nothing changed.
Undo string
}
Saved is what an Update did.
type Snapshot ¶
type Snapshot struct {
Document *store.Document
Tree *rolo.Tree
// Trash is the Trash as the Editor should see it: purged as of Now. An
// expired entry nothing needs is still stored — and restorable — until
// the next Trash write, but it must not be listed or counted. Reading it
// writes nothing.
Trash *store.Trash
Settings *store.Settings
// Now is the one clock reading this Snapshot was taken at. A write uses
// it for everything it dates, so a deletion and the purge beside it agree.
Now time.Time
// contains filtered or unexported fields
}
Snapshot is the served Directory at one moment. Nothing it points at is ever mutated; a write that wants to change something builds a new value.
type Writer ¶
Writer persists a change. It is handed the state being replaced as well as the new one, so it can tell which files changed and order the writes so that a crash cannot lose a Household (store.Persist, ADR-0012). store.Paths satisfies it.
It is called synchronously, inside the request that made the change: the atomic write in internal/store protects a write that has begun, and graceful shutdown waits for in-flight requests, so a write handed to a goroutine would escape both.