Skip to main content

Store

Struct Store 

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

A local LFS object store rooted at <lfs_dir> (typically .git/lfs).

May reference any number of alternate stores (typically the LFS objects of a git clone --shared source) and will materialize a hit from one of them into the local store on demand. See Store::with_references.

Implementations§

Source§

impl Store

Source

pub fn new(lfs_dir: impl Into<PathBuf>) -> Self

Create a store rooted at the given LFS directory. The directory is not created eagerly; subdirectories are created on demand as objects land.

Source

pub fn with_shared_repository(self, value: &str) -> Self

Apply core.sharedRepository semantics to objects this store commits.

value is the literal string from git config (group, everybody, octal 0660, etc). Unrecognized values fall back to honoring the process umask. Resets any prior policy on this Store.

Source

pub fn with_references(self, refs: impl IntoIterator<Item = PathBuf>) -> Self

Attach alternate lfs/objects/ directories that the store may hardlink-or-copy from when a local lookup misses.

Used by git clone --shared setups so the new repo can read the source’s existing LFS objects without re-downloading.

Pass git_lfs_git::lfs_alternate_dirs (<git-dir>/objects/info/alternates resolved to LFS-objects dirs) at construction.

Source

pub fn root(&self) -> &Path

Root LFS directory.

Source

pub fn tmp_dir(&self) -> PathBuf

Directory holding temp files for in-flight inserts.

Source

pub fn incomplete_dir(&self) -> PathBuf

Directory holding partial or in-progress downloads.

Files are named <oid>.part and persist across process invocations so a later attempt can pick up where a prior one left off (issuing a Range: request). Mirrors upstream’s incomplete/ layout.

Source

pub fn incomplete_path(&self, oid: Oid) -> PathBuf

Path to the partial-download file for oid.

The file may not exist; the caller is responsible for creating and writing it.

Source

pub fn commit_partial(&self, oid: Oid, partial: &Path) -> Result<()>

Atomically move a fully-downloaded partial file into its final object-path location.

The caller is responsible for confirming the file’s bytes hash to oid first; this is a pure rename. Clobbers any existing file at the destination, see insert_verified for the rationale.

Source

pub fn cleanup_tmp_objects(&self)

Sweep <root>/tmp/ for stale temp files left behind by interrupted prior runs.

Filenames matching <64-hex>-<random> whose object is already complete in the store are removed unconditionally (upstream’s in-flight download tempfile shape); everything else older than an hour is pruned.

Best-effort: the dir not existing, or any individual remove failing, is silently ignored. Intended to run once per command invocation, before the command’s main work, so an interrupted prior run doesn’t leak temp files indefinitely (matches upstream’s lfs.cleanupTempFiles startup task in fs/cleanup.go).

Per-file rules, mirroring upstream:

  1. Filenames starting with <64-hex>- whose object is already complete in the store are removed unconditionally (interrupted-rename leftovers).
  2. Otherwise, files older than 1 hour are removed unless they live in a subdirectory whose own mtime is fresher than 1 hour, since active processes may have stale-looking files they still hold open (hard-linked across repos). Files directly under tmp/ are exempt from the subdir-age short-circuit since we modify the top-level tmp dir often enough that it would never expire.
Source

pub fn object_path(&self, oid: Oid) -> PathBuf

Where the object with this OID lives on disk.

For Oid::EMPTY this returns the platform null device, mirroring upstream’s behavior so callers can open an empty object without special-casing.

Source

pub fn contains(&self, oid: Oid) -> bool

Check if this object is present locally as a regular file.

The empty OID is always considered present. If the local copy is missing but an alternate store has the object, materializes it locally first.

Source

pub fn contains_with_size(&self, oid: Oid, size: u64) -> bool

Check if the object is present and its on-disk size matches size.

Used to detect partial/corrupted local copies. Like contains, will fault in a matching alternate-store object on demand.

Source

pub fn each_object(&self) -> Result<Vec<(Oid, u64)>>

Walk every object file in the store, yielding (oid, size_on_disk).

Traverses the sharded objects/<aa>/<bb>/<oid> layout. Filenames that don’t parse as 64-char SHA-256 hex are silently skipped, as are unexpected directories. The store directory not existing is not an error; the result is just empty.

Source

pub fn open(&self, oid: Oid) -> Result<File>

Open an object for reading.

Errors with io::ErrorKind::NotFound if the object isn’t in the store. Faults in from a reference store if needed.

Source

pub fn insert(&self, src: &mut impl Read) -> Result<(Oid, u64), StoreError>

Stream src into the store, computing SHA-256 as we go, returning the resulting OID and byte count.

This is the clean-filter path: the OID isn’t known until the content has been hashed. Inserting bytes that already exist locally under the same OID is a no-op; in particular, the existing on-disk file (which may be a hardlink into an alternate store) is left untouched.

Source

pub fn insert_verified( &self, expected: Oid, src: &mut impl Read, ) -> Result<u64, StoreError>

Stream src into the store, requiring the resulting hash to equal expected.

On mismatch, returns StoreError::HashMismatch and the temp file is dropped without being committed.

This is the download path: we know the OID upfront and must verify what the server sent.

Source

pub fn prepare_incomplete_dir(&self) -> Result<()>

Ensure <root>/incomplete/ exists with the configured directory mode.

Call before staging .part files yourself so the resulting directory honors any core.sharedRepository policy on this Store.

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
Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<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, 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> 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 = Infallible

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.