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
impl Store
Sourcepub fn new(lfs_dir: impl Into<PathBuf>) -> Self
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.
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.
Sourcepub fn with_references(self, refs: impl IntoIterator<Item = PathBuf>) -> Self
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.
Sourcepub fn incomplete_dir(&self) -> PathBuf
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.
Sourcepub fn incomplete_path(&self, oid: Oid) -> PathBuf
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.
Sourcepub fn commit_partial(&self, oid: Oid, partial: &Path) -> Result<()>
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.
Sourcepub fn cleanup_tmp_objects(&self)
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:
- Filenames starting with
<64-hex>-whose object is already complete in the store are removed unconditionally (interrupted-rename leftovers). - 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.
Sourcepub fn object_path(&self, oid: Oid) -> PathBuf
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.
Sourcepub fn contains(&self, oid: Oid) -> bool
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.
Sourcepub fn contains_with_size(&self, oid: Oid, size: u64) -> bool
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.
Sourcepub fn each_object(&self) -> Result<Vec<(Oid, u64)>>
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.
Sourcepub fn open(&self, oid: Oid) -> Result<File>
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.
Sourcepub fn insert(&self, src: &mut impl Read) -> Result<(Oid, u64), StoreError>
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.
Sourcepub fn insert_verified(
&self,
expected: Oid,
src: &mut impl Read,
) -> Result<u64, StoreError>
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.
Sourcepub fn prepare_incomplete_dir(&self) -> Result<()>
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.