Skip to main content

install_read_mem

Function install_read_mem 

Source
pub fn install_read_mem(
    archive_path: &Path,
    target: TargetMem<'_>,
    ctx: &CommitContext<'_>,
    commit_message: &str,
    writable_mem_names: &[&str],
) -> Result<InstallOutcome, InstallError>
Expand description

Install a sealed mem archive into the global cache and register it in a writable mem’s config. Accepts the .mem archive format.

Two independent side effects, both idempotent:

  1. If the content-addressed cache file does not exist: run the submitted bytes through validate_and_normalize_archive and write the validator’s canonical_bytes via a .tmp sibling + atomic rename. A mid-write crash leaves the temp file behind, never a partial cache file. Existing cache files are left untouched — overwrite-on-newer-version is an app-level update flow, not a CLI install semantic. Users who want to force-replace can delete the cache file first.
  2. If the target mem’s config does not already list this mem under readMems, add an entry with source: { type: "local" }. Existing entries are left untouched so re-running install never clobbers a type: "url" (etc.) source the user configured by hand.

The target parameter selects where the registration lands:

  • TargetMem::Disk(mem_dir) writes the updated config back to <mem_dir>/.memstead/config.json (legacy disk shape).
  • TargetMem::MemRepo { workspace_root, mem_name } commits the updated configs/<mem_name>.json to mem-repo-git:main (post- cutover shape).

ctx and commit_message are used only by the MemRepo arm — the disk arm rewrites the file via the existing config-update path which has its own (file-mtime-based) provenance trail.

Returns an InstallOutcome describing which effects fired. The authoritative mem name comes from the validator’s approved config, not from the submitted filename or caller argument.