WeaveDocs
Locus

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.

Note

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.rs
  • CreateOptions — models/locus/src/ops.rs
  • FileEntry — models/locus/src/entry.rs
  • FileMetadata — models/locus/src/entry.rs
  • JournalRecord — models/locus/src/journal.rs
  • JournalStore — models/locus/src/journal.rs
  • Locus — models/locus/src/locus.rs
  • LocusConfig — models/locus/src/config.rs
  • MountOptions — models/locus/src/config.rs
  • MountPoint — models/locus/src/mount.rs
  • MountTable — models/locus/src/mount.rs
  • OpenOptions — 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(())
}