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_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 cleanup_tmp_objects(&self)

Sweep <root>/tmp/objects/ (upstream’s path for in-flight download temp files: <oid>-<random>) and remove any whose leading 64-char OID is already complete in the store.

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).

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

true 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

true 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.

Used by git lfs prune and (eventually) fsck --orphaned.

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. Returns the resulting OID and byte count.

This is the clean-filter path: we don’t know the OID until after the content is hashed.

If the resulting OID is already present locally, the temp file is dropped without persisting. The store is content-addressed, so an existing file at that path is necessarily the same bytes; skipping tmp.persist here preserves any hardlink already at the destination (a rename swaps a fresh inode in, which would break the link to the alternate-store source).

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.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 · 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.