Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

The global content-addressable store, owned by aube.

Default location: $XDG_DATA_HOME/aube/store/v1/files/ (falling back to ~/.local/share/aube/store/v1/files/). Files are stored by BLAKE3 hash with two-char hex directory sharding. (Tarball-level integrity is still SHA-512 because that’s the format the npm registry returns; the per-file CAS key is an internal choice.)

Layout under the store-version directory (v1/):

  • v1/files/ — CAS shards, content-addressed by BLAKE3 hex
  • v1/index/ — cached package indexes (kept next to files/ so a single backup/mount captures the whole store; matches pnpm’s ~/.pnpm-store/v11/{files,index.db} grouping)

cache_dir (the cacheDir setting, default: the platform cache dir) still holds genuinely regenerable caches: the global virtual store and packument metadata.

Implementations§

Source§

impl Store

Source

pub fn ensure_shards_exist(&self) -> Result<(), Error>

Ensure every two-char shard directory under the CAS root exists. CAS files live under <root>/<ab>/<cdef...> for 256 possible prefixes. Running this once before a batch of import_bytes calls lets the per-file hot path skip the mkdirp(parent) stat entirely (the parent is guaranteed to exist). On APFS that removes ~7.5k redundant stat syscalls per cold install — the mkdirp inside xx::file::write was the #1 stat hotspot in a dtrace profile.

Cheap to call repeatedly: each create_dir_all is a no-op when the directory already exists, but callers should still hoist the call out of tight loops.

Source

pub fn import_bytes( &self, content: &[u8], executable: bool, ) -> Result<StoredFile, Error>

Import a single file’s content into the store. Returns the stored file info.

Hot path on cold installs: callers should invoke Store::ensure_shards_exist once before a batch of imports so this function can skip the per-file mkdirp. When shards don’t exist yet, the create_new open will fail with NotFound; we fall back to the slow path for correctness.

Source

pub fn import_bytes_gated( &self, rel_path: &str, content: &[u8], executable: bool, ) -> Result<StoredFile, Error>

Import a tar entry’s content, applying OS-level transparent compression to the entries the store-compression gate selects.

When AUBE_COMPRESS_STORE is unset this is exactly Store::import_bytes — same CAS key, same write path. When it is set and rel_path + size match the gate, the entry is first unwrapped if it is a napi --compress hybrid (so the CAS stores the raw .node, not the wrapper) and then written into the CAS as a transparently-compressed file in ONE pass via decmpfs::compress_bytes — never a write-then-read-back. The kernel decompresses on read, so the stored file keeps its logical size and exact bytes; cas_file_matches_len and the BLAKE3 CAS key are computed against that logical content, unchanged.

Fail-soft: compress_bytes itself falls back to a plain atomic write on an unsupported FS or any backend error, so a matched entry always lands. The gate firing only changes how the bytes are stored, never whether they are.

Source§

impl Store

Source

pub fn load_index( &self, name: &str, version: &str, integrity: Option<&str>, ) -> Option<PackageIndex>

Load a cached package index, if it exists.

integrity, when Some, is the registry-advertised SRI digest (sha512-, or legacy sha1- / sha256- / sha384-) of the tarball these cache files came from — part of the cache key so the same (name, version) resolved from different sources (npm registry vs. github codeload vs. a proxy that served different bytes) can’t alias on disk and return each other’s file lists to the linker. None falls back to an unsuffixed <name>@<version>.json key so packages fetched through a registry proxy that strips dist.integrity can still warm-install — an integrity-less setup is already a degraded mode the user opted into via strict-store-integrity=false.

Source

pub fn load_index_verified( &self, name: &str, version: &str, integrity: Option<&str>, ) -> Option<PackageIndex>

Load a package index, optionally verifying that all store files still exist. The verified variant is slower (stat per file) but detects a corrupted store.

Source

pub fn invalidate_cached_index( &self, name: &str, version: &str, integrity: Option<&str>, ) -> Result<bool, Error>

Delete the cached package index for (name, version, integrity) if it exists. Used as a recovery hatch when the linker discovers a CAS shard referenced by the index has gone missing — the cached JSON points at a dead store_path, so the next install must re-derive the index by re-importing the tarball.

Ok(true) when an entry was removed; Ok(false) when there was nothing to remove (or the coordinate was invalid). Errors surface only on real I/O failure, not on the missing-file case.

Source

pub fn save_index( &self, name: &str, version: &str, integrity: Option<&str>, index: &PackageIndex, ) -> Result<(), Error>

Save a package index to the cache.

See load_index for the semantics of integrity and the integrity-less fallback.

Source§

impl Store

Source

pub fn import_directory(&self, dir: &Path) -> Result<PackageIndex, Error>

Import every file under a directory into the store, producing a PackageIndex keyed by paths relative to dir. Used by file: deps pointing at an on-disk package directory. Common noise (.git, node_modules) is skipped so local packages don’t drag the target’s own installed deps into the virtual store.

Source

pub fn import_tarball( &self, tarball_bytes: &[u8], ) -> Result<PackageIndex, Error>

Import a tarball (.tgz) into the store. Returns a PackageIndex mapping relative paths to stored files.

Two-phase: serial tar walk that stages (rel_path, content, executable) triples (the tar reader is inherently sequential), then a CAS-write batch. When the staged batch crosses [PARALLEL_IMPORT_THRESHOLD] entries, the writes fan out via rayon::par_iter — the per-file CAS path is O_CREAT|O_EXCL and uses a shared &Store, so parallel writers are race-safe by construction (EEXIST on content collision is a success path because BLAKE3 paths are content-addressed).

AUBE_DISABLE_PARALLEL_IMPORT=1 forces the serial path. Use it as a regression killswitch if a future rayon scope inversion (linker symlink pass running concurrently) shows contention. Below the threshold the small-tarball overhead of rayon dispatch outweighs the win, so the cutover is conditional.

Source

pub fn import_tarball_reader<R: Read>( &self, compressed_reader: R, ) -> Result<PackageIndex, Error>

Streaming variant. Accepts any compressed-tarball Read source so callers can pipe HTTP body chunks straight through without buffering the whole archive into memory first. Caps and CAS publish semantics match import_tarball exactly.

Source§

impl Store

Source

pub fn default_location() -> Result<Self, Error>

Open the store at the platform default location (see dirs::store_dir and dirs::cache_dir).

aube’s own CLI resolves storeDir / cacheDir / globalVirtualStoreDir first and goes through Store::with_dirs; this is the entry point for embedders that just want the same directories a default install would use.

Source

pub fn with_root(root: PathBuf) -> Result<Self, Error>

Open the store with an explicit CAS root, keeping the platform cache dir for the global virtual store and packument caches. Equivalent to with_dirs(root, dirs::cache_dir()).

Source

pub fn with_dirs(root: PathBuf, cache_dir: PathBuf) -> Self

Open the store with an explicit CAS root and cache dir. Used when a user overrides storeDir (the CAS) and/or cacheDir (the global virtual store + packument caches); the two are independent settings, but the global virtual store hardlinks out of the CAS, so a caller pointing them at different volumes gives up the hardlink fast path.

root is the CAS shard directory (<storeDir>/v1/files), not the user-facing store dir. The global virtual store lands under cache_dir unless Store::with_virtual_store_dir moves it.

Source

pub fn with_virtual_store_dir(self, dir: PathBuf) -> Self

Point the global virtual store somewhere other than <cache_dir>/virtual-store (the globalVirtualStoreDir setting). The path is used verbatim.

Source

pub fn at(root: PathBuf) -> Self

Open the store at a specific path (cache dir derived from store root). Used by tests that need a fully isolated layout; production code should prefer with_dirs.

Source

pub fn root(&self) -> &Path

Source

pub fn store_v1_dir(&self) -> PathBuf

The store-version directory containing files/ and index/.

For the default layout this is <storeDir>/v1/ (parent of root, which is the files/ subdir). Matches the granularity of pnpm store path — a single cache-mount or backup covering this directory captures both the CAS shards and the cached package indexes, so they cannot drift apart.

Falls back to root itself when root has no parent (only possible at the filesystem root, which is never a real store).

Source

pub fn index_dir(&self) -> PathBuf

Directory for cached package indexes. Lives next to files/ at <v1_dir>/index/ so the whole store is one mount/backup unit. Public so introspection commands (aube find-hash, aube store status, aube store prune) can walk it directly.

Source

pub fn legacy_index_dir(&self) -> PathBuf

Legacy index location at $XDG_CACHE_HOME/aube/index/, where aube wrote cached package indexes before they were moved next to the CAS files. Used only by [migrate_legacy_index_dir]; new code should always go through [index_dir].

Source

pub fn legacy_index_migration_needed(&self) -> bool

Whether opening this store for writes would migrate the legacy index.

Source

pub fn maintenance_lock_path(&self) -> PathBuf

Source

pub fn prepare_for_write(&self) -> Result<(), Error>

Acquire the shared writer lease and perform any pending legacy-index migration. The lease is retained by this Store and all of its clones.

Source

pub fn lock_for_maintenance(&self) -> Result<StoreMaintenanceGuard, Error>

Acquire an exclusive lease for a complete prune plan/apply operation.

Source

pub fn migrate_legacy_index_for_maintenance( &self, _guard: &StoreMaintenanceGuard, )

Apply the legacy-index migration while an exclusive maintenance lease is held. Used by real prune after its candidate plan is complete.

Source

pub fn virtual_store_dir(&self) -> PathBuf

Directory for the global virtual store (materialized packages). <cacheDir>/virtual-store/ unless globalVirtualStoreDir moved it, so it follows cacheDir by default.

Source

pub fn packument_cache_dir(&self) -> PathBuf

Directory for cached packument metadata (abbreviated/corgi format). Versioned so we can bump the schema without breaking old caches — old caches at older versions stay around until manually pruned.

Source

pub fn packument_full_cache_dir(&self) -> PathBuf

Directory for cached full packument JSON (non-corgi) used by human-facing commands like aube view that need fields the resolver doesn’t parse (description, repository, license, keywords, maintainers). Separate from packument_cache_dir because the corgi and full responses have different shapes.

Source

pub fn has(&self, integrity: &str) -> bool

Check if a file with the given integrity hash exists in the store.

Source

pub fn file_path_from_integrity(&self, integrity: &str) -> Option<PathBuf>

Get the path to a file in the store by its integrity hash.

Source

pub fn file_path_from_hex(&self, hex_hash: &str) -> PathBuf

Get the path to a file in the store by its hex hash.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more