Documentation
¶
Overview ¶
Package workdir is a repo folder as publish and pull see it: the files a publish carries, hashed into a tree, and the safe writing of a merge into them, with a backup to undo it. docs/designs/publish.md is its design.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(dir, backupDir string, changes []Change, begin func(before map[string]string) error) error
Apply writes changes into the folder at dir, as safely as it can:
- Every path is checked first (CheckPath). One unsafe path writes nothing.
- The current version of each path that will change is copied into backupDir, named by its blob id, never by its path: a backup named models/orders.aml would be read as part of the repo by anything that scans for .aml files.
- begin is called with each changed path's blob id before the merge, "" for one that didn't exist, for the caller to record before anything is written: a write cut short can then be undone (Restore).
- Each file is written through a temporary file and a rename, keeping an existing file's mode; deleted paths are removed.
Every file operation goes through an os.Root opened at dir or backupDir, so none can leave them, by ".." or a symlink, even one made after the check.
func CheckPath ¶
CheckPath refuses a path anfra won't write in the folder at dir: one that isn't a clean, relative, slash-separated path publish would send, or that leads through a symlink, or onto something other than a regular file.
Types ¶
type NotRegularError ¶
type NotRegularError struct {
// Files are the paths, each with what it is: "models/a.aml (a symlink)".
Files []string
}
NotRegularError names files of the repo that aren't regular files: a symlink or anything else. They're refused by name, never skipped, which would read as deleted, nor followed out of the repo.
func (*NotRegularError) Error ¶
func (e *NotRegularError) Error() string
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a folder's files as a merge sees them: each selected file's path and blob id, as git names its content (repoformat.BlobID).
func (Tree) ReadBlob ¶
ReadBlob reads a file's content by blob id, from a path holding it. A file changed since Read fails: the merge would otherwise work from content other than what it classified.
func (Tree) Unselected ¶
Unselected is those of paths that exist in the folder but aren't among its selected files: a symlink, or a file this anfra doesn't publish, such as one an older anfra did. A merge would read each as deleted, and the next publish would delete it from the org, so callers stop and name them.
type UnsafePathError ¶
UnsafePathError is a path a merge would write that anfra refuses: one that isn't a repo file publish would send, or that would reach outside the folder, through a symlink or otherwise. Nothing is written when there's one.
func (*UnsafePathError) Error ¶
func (e *UnsafePathError) Error() string