Skip to main content

File

Struct File 

Source
pub struct File<T = MMap> { /* private fields */ }
Expand description

A representation of an index file for multiple packs at the same time, typically stored in a file named ‘multi-pack-index’.

Implementations§

Source§

impl<T> File<T>
where T: FileData,

Access methods

Source

pub fn version(&self) -> Version

Returns the version of the multi-index file.

Source

pub fn path(&self) -> &Path

Returns the path from which the multi-index file was loaded.

Note that it might have changed in the mean time, or might have been removed as well.

Source

pub fn num_indices(&self) -> PackIndex

Returns the amount of indices stored in this multi-index file. It’s the same as File::index_names().len(), and returned as one past the highest known index.

Source

pub fn num_objects(&self) -> EntryIndex

Returns the total amount of objects available for lookup, and returned as one past the highest known entry index

Source

pub fn object_hash(&self) -> Kind

Returns the kind of hash function used for object ids available in this index.

Source

pub fn checksum(&self) -> ObjectId

Returns the checksum over the entire content of the file (excluding the checksum itself).

It can be used to validate it didn’t change after creation.

Source

pub fn index_names(&self) -> &[PathBuf]

Return all names of index files (*.idx) whose objects we contain.

The corresponding pack can be found by replacing the .idx extension with .pack.

Source§

impl<T> File<T>
where T: FileData,

Source

pub fn oid_at_index(&self, index: EntryIndex) -> &oid

Return the object id at the given index, which ranges from 0 to File::num_objects().

Source

pub fn lookup_prefix( &self, prefix: Prefix, candidates: Option<&mut Range<EntryIndex>>, ) -> Option<PrefixLookupResult>

Given a prefix, find an object that matches it uniquely within this index and return Some(Ok(entry_index)). If there is more than one object matching the object Some(Err(()) is returned.

Finally, if no object matches the index, the return value is None.

Pass candidates to obtain the set of entry-indices matching prefix, with the same return value as one would have received if it remained None. It will be empty if no object matched the prefix.

Source

pub fn lookup(&self, id: impl AsRef<oid>) -> Option<EntryIndex>

Find the index ranging from 0 to File::num_objects() that belongs to data associated with id, or None if it wasn’t found.

Use this index for finding additional information via File::pack_id_and_pack_offset_at_index().

Source

pub fn pack_id_and_pack_offset_at_index( &self, index: EntryIndex, ) -> (PackIndex, Offset)

Given the index ranging from 0 to File::num_objects(), return the pack index and its absolute offset into the pack.

The pack-index refers to an entry in the index_names list, from which the pack can be derived.

Source

pub fn iter(&self) -> impl Iterator<Item = Entry> + '_

Return an iterator over all entries within this file.

Source§

impl<T> File<T>
where T: FileData,

Source

pub fn verify_checksum( &self, progress: &mut dyn Progress, should_interrupt: &AtomicBool, ) -> Result<ObjectId, Error>

Validate that our checksum() matches the actual contents of this index file, and return it if it does.

Source

pub fn verify_integrity_fast( &self, progress: &mut dyn DynNestedProgress, should_interrupt: &AtomicBool, ) -> Result<ObjectId, Error>

Similar to verify_integrity() but without any deep inspection of objects.

Instead we only validate the contents of the multi-index itself.

Source

pub fn verify_integrity<C, F>( &self, progress: &mut dyn DynNestedProgress, should_interrupt: &AtomicBool, options: Options<F>, ) -> Result<Outcome, Error<Error>>
where C: DecodeEntry, F: Fn() -> C + Send + Clone,

Similar to crate::Bundle::verify_integrity() but checks all contained indices and their packs.

Note that it’s considered a failure if an index doesn’t have a corresponding pack.

Source§

impl File<MMap>

Initialization

Source

pub fn at( path: impl AsRef<Path>, alloc_limit_bytes: Option<usize>, ) -> Result<Self, Error>

Open the multi-index file at the given path.

alloc_limit_bytes bounds each allocation caused by user-controlled on-disk data, useful for untrusted input. Use None to disable the limit.

Source§

impl<T> File<T>
where T: FileData,

Source

pub fn from_data( data: T, path: PathBuf, alloc_limit_bytes: Option<usize>, ) -> Result<Self, Error>

Instantiate a multi-index file from data as assumed to be read or memory-mapped from path.

alloc_limit_bytes bounds each allocation caused by untrusted on-disk multi-index data. Use None to disable the limit.

It is used to reject reserving the output Vec<PathBuf> if its capacity estimate exceeds the limit, and to reject any single path entry whose byte length exceeds the limit before turning it into a PathBuf.

Auto Trait Implementations§

§

impl<T> Freeze for File<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for File<T>
where T: RefUnwindSafe,

§

impl<T> Send for File<T>
where T: Send,

§

impl<T> Sync for File<T>
where T: Sync,

§

impl<T> Unpin for File<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for File<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for File<T>
where T: UnwindSafe,

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