File Operations
File Operations in Locus. File and directory model with metadata, mounts, streams, watchers, journals, permission modes, and governance.
Purpose
File and directory model with metadata, mounts, streams, watchers, journals, permission modes, and governance.
This page follows the real source shape for Locus and explains the workflow a developer is likely to use first.
Storage contract
Document persistence format, integrity checks, read/write ordering, idempotency, compaction or repair behavior, and how callers recover from partial failures. This section should answer what data is durable and what can be reconstructed.
locus_write_file is two journal entries: a blob write followed by a metadata block. Crash recovery rolls back any half-completed write; the previous file version is preserved.
Primary types to know
AllowAllLocusPolicy— models/locus/src/policy.rsCreateOptions— models/locus/src/ops.rsFileEntry— models/locus/src/entry.rsFileMetadata— models/locus/src/entry.rsJournalRecord— models/locus/src/journal.rsJournalStore— models/locus/src/journal.rsLocus— models/locus/src/locus.rsLocusConfig— models/locus/src/config.rsMountOptions— models/locus/src/config.rsMountPoint— models/locus/src/mount.rsMountTable— models/locus/src/mount.rsOpenOptions— models/locus/src/ops.rs
Example shape
use weave_sdk::prelude::*;
#[tokio::main]
async fn main() -> WeaveResult<()> {
// Bring up a node and open a Locus drive named "workspace".
let node = WeaveNode::builder()
.namespace("l1fe")
.identifier("locus-file-ops")
.storage_dir("/tmp/weave-locus-file-ops")
.build()
.await?;
node.open_locus("workspace").await?;
// Create, write, list, read, and remove — the round-trip every caller exercises first.
node.locus_mkdir("workspace", "/docs").await?;
node.locus_write_file("workspace", "/docs/README.md", b"# hello").await?;
node.locus_write_file("workspace", "/docs/draft.txt", b"work in progress").await?;
let entries = node.locus_readdir("workspace", "/docs").await?;
let bytes = node.locus_read_file("workspace", "/docs/README.md").await?;
node.locus_remove("workspace", "/docs/draft.txt").await?;
let after = node.locus_readdir("workspace", "/docs").await?;
println!(
"entries_before={} README.md={} bytes entries_after={}",
entries.len(),
bytes.len(),
after.len(),
);
Ok(())
}