[][src]Struct asuran::repository::backend::common::generic_flatfile::GenericFlatFile

pub struct GenericFlatFile<F: Read + Write + Seek + 'static> {
    file: F,
    path: PathBuf,
    chunk_settings: ChunkSettings,
    index: HashMap<ChunkID, SegmentDescriptor>,
    length_map: HashMap<SegmentDescriptor, u64>,
    manifest: Vec<StoredArchive>,
    entry_footer_data: EntryFooterData,
    chunk_settings_modified: bool,
    enc_key: EncryptedKey,
    key: Key,
    chunk_headers: HashMap<SegmentDescriptor, ChunkHeader>,
    header_offset: u64,
    seen_versions: HashSet<(Version, Uuid)>,
}

A view over a generic FlatFile backend.

This generic backend can accept any (owned) Read + Write + Seek, and will implement the same binary format on top of it.

See module level documentation for details.

Fields

file: Fpath: PathBufchunk_settings: ChunkSettingsindex: HashMap<ChunkID, SegmentDescriptor>length_map: HashMap<SegmentDescriptor, u64>manifest: Vec<StoredArchive>entry_footer_data: EntryFooterDatachunk_settings_modified: boolenc_key: EncryptedKeykey: Keychunk_headers: HashMap<SegmentDescriptor, ChunkHeader>header_offset: u64seen_versions: HashSet<(Version, Uuid)>

Implementations

impl<F: Read + Write + Seek + 'static> GenericFlatFile<F>[src]

pub fn new_raw(
    file: F,
    path: impl AsRef<Path>,
    settings: Option<ChunkSettings>,
    key: Key,
    enc_key: Option<EncryptedKey>
) -> Result<GenericFlatFile<F>>
[src]

Opens up a new GenericFlatFile over the provided Read + Write + Seek

If the given 'file' is empty, it will write the initial headers, otherwise, it will walk through all the headers and footers in the repository, and parse them in to their needed forms.

If the given 'file' is empty, and thus the repository is being initialized, chunk settings and an encrypted key must be passed.

Errors

  • If an underlying I/O Error occurs
  • If the caller is initializing a repository, but did not provide chunk settings or an encrypted key, Err(ManifestError)
  • If the caller provides an encrypted key for an already initialized repository
  • If decoding of the encrypted key or any of the headers/footers fails Err(FlatFileError)
  • If any of the chunks described by the footers do not have an associated ChunkHeader
  • If an already initalized repository does not contain any footers

pub fn load_encrypted_key(file: F) -> Result<EncryptedKey>[src]

Attempts to read an EncryptedKey from the header of the provided repository file

Errors

  • If an underlying I/O error occurs
  • If decoding the EncryptedKey fails

Trait Implementations

impl<F: Read + Write + Seek + 'static> Debug for GenericFlatFile<F>[src]

impl<T: Read + Write + Seek + 'static> Drop for GenericFlatFile<T>[src]

impl<F: Read + Write + Seek + 'static> SyncBackend for GenericFlatFile<F>[src]

type SyncManifest = Self

type SyncIndex = Self

fn write_key(&mut self, _key: EncryptedKey) -> Result<()>[src]

This operation is not currently supported for FlatFile repositories, so we just return an error

fn read_key(&mut self) -> Result<EncryptedKey>[src]

Return the cached EncryptedKey

fn read_chunk(&mut self, location: SegmentDescriptor) -> Result<Chunk>[src]

Glue together information from the cached index, the length_map, and the chunk_headers map to find the chunk in the file and reconstruct it.

Errors

  • If there is an underlying I/O error
  • If the location is not present in the length map (the chunk has not been seen before, or it has not been written with write_chunk
  • If the header is not present in the chunk_headers map

impl<F: Read + Write + Seek + 'static> SyncIndex for GenericFlatFile<F>[src]

fn lookup_chunk(&mut self, id: ChunkID) -> Option<SegmentDescriptor>[src]

Simply looks up the chunk in the cached index map

fn set_chunk(&mut self, id: ChunkID, location: SegmentDescriptor) -> Result<()>[src]

Updates the cached index map, as well as adds the chunk to the EntryFooterData

Errors

Will return Err if the Chunk had not been previously written with write_chunk, and thus has an unknown length.

fn known_chunks(&mut self) -> HashSet<ChunkID>[src]

Collects the keys from the cached index map into a HashSet

fn commit_index(&mut self) -> Result<()>[src]

Flush the EntryFooterDisk to disk and make a new one

fn chunk_count(&mut self) -> usize[src]

Returns the size of the cached index map

impl<F: Read + Write + Seek + 'static> SyncManifest for GenericFlatFile<F>[src]

type Iterator = IntoIter<StoredArchive>

fn last_modification(&mut self) -> Result<DateTime<FixedOffset>>[src]

Assumes archives were written in chronological order, and returns the timestamp of the last archive written.

Errors

Will return Err if there are no archives in this repository

fn chunk_settings(&mut self) -> ChunkSettings[src]

Returns the cached ChunkSettings stored in the struct

fn write_chunk_settings(&mut self, settings: ChunkSettings) -> Result<()>[src]

Modifies the cached ChunkSettings, as well as the ones in the EntryFooterData. Additionally sets the dirty flag on the chunk settings, so if only the chunk settings were modified, this change will still get persisted to the repository.

fn archive_iterator(&mut self) -> Self::Iterator[src]

Clones the cached manifest Vec and turns it into an iterator

fn write_archive(&mut self, archive: StoredArchive) -> Result<()>[src]

Adds the archive to the cached manifest Vec, as well as to the EntryFooterData

fn touch(&mut self) -> Result<()>[src]

This repository type does not support touching, so this does nothing

Auto Trait Implementations

impl<F> RefUnwindSafe for GenericFlatFile<F> where
    F: RefUnwindSafe

impl<F> Send for GenericFlatFile<F> where
    F: Send

impl<F> Sync for GenericFlatFile<F> where
    F: Sync

impl<F> Unpin for GenericFlatFile<F> where
    F: Unpin

impl<F> UnwindSafe for GenericFlatFile<F> where
    F: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]