Documentation
¶
Overview ¶
Package edit is the single disk-writing surface in weft. It hands a page's .md file off to the user's editor and detects whether the file changed on return. No other package in the project writes to disk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureFile ¶
EnsureFile creates an empty file at path with mode 0o644 if it does not exist. Returns (true, nil) on create, (false, nil) if the file already existed, or (false, err) for any other stat/write failure (including the case where path resolves to a directory). This is the create-today-journal hook.
func SnapshotMtime ¶
SnapshotMtime returns the file's modification time, or time.Time{} (the zero value) if the file does not exist. The zero return is load-bearing: t0.IsZero() means the file was absent at snapshot time, which tells the caller (the App's editCurrent) that it should create the file before handing it to the editor. A non-zero t0 means the file was on disk before the user pressed e.
func WriteFile ¶
WriteFile writes data to path atomically, creating the parent directory if it does not yet exist. It is the second deliberate write path in the project (alongside the EnsureFile bootstrap); all disk writes still funnel through package edit.
The write goes to a temp file in the destination directory and is moved into place with os.Rename, so a crash mid-write leaves the original intact rather than truncated — load-bearing now that linkify writes to files other than the page being edited. The destination's existing permission bits are preserved (a new file gets defaultFileMode), since the temp file is born 0o600. "Preserved" means the rwx permission bits only: setuid/setgid/sticky are dropped, and owner/group become the weft process's user (the temp file is created by this process and renamed over the original) — acceptable for a single-user local graph, which is weft's only caller.
path is assumed to be a regular file (the only kind weft's callers pass) — renaming over a symlink replaces the link, not its target. No fsync is done: rename guarantees atomicity against a process crash, which is the failure this protects against; durability against power loss is out of scope for a local notes TUI.
Types ¶
type Env ¶
Env carries the configuration the editor-resolver reads. Decoupled from os.Getenv so tests can inject a fixed env without touching process state.