Skip to main content

ensure_clone

Function ensure_clone 

Source
pub fn ensure_clone(canonical_url: &str) -> Result<PathBuf, CacheError>
Expand description

Ensure a local clone of canonical_url exists and is up to date; returns the repo’s local path.

An existing path at the cache-key slot is only ever treated as a fetchable cache slot when it already passes is_owned_entry – a .git directory sitting at that path without the .khive-last-used marker (a foreign directory that happens to collide with the cache key, or a directory a crashed prior run left in a pre-touch state) is refused with CacheError::UnsafeToReplace rather than fetched into or adopted (issue #765 review round-2 [High]-1). A fresh clone is written into a private staging directory first (git clone --filter=blob:none), measured there, marked with .khive-last-used there, and only moved into the addressable <root>/<cache_key>/ slot once it is under the cap and already carries its ownership marker – an oversized clone never enters the cache slot, never participates in evict_lru’s accounting, and is removed from staging immediately; a process interruption between the clone and the rename can never leave a live, markerless slot behind.

A repo that grew past the per-clone cap since it was last fetched is evicted from the cache slot on the spot, through the same ownership- guarded remove_owned_entry every other repair path uses, propagating any cleanup/ownership failure instead of discarding it.

Runs LRU eviction over the rest of the cache after a successful clone/fetch (this clone is exempt from its own eviction pass).