pub struct SnapshotExtractor { /* private fields */ }Expand description
Extracts tar.xz snapshot archives with security validations.
Provides safe extraction by validating file paths to prevent directory traversal attacks and ensuring only expected database files are extracted.
Implementations§
Source§impl SnapshotExtractor
impl SnapshotExtractor
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new extractor with predefined expected files.
Expected files include SQLite database and WAL files:
hopr_logs.db- Main database filehopr_logs.db-wal- Write-Ahead Log filehopr_logs.db-shm- Shared memory file
Sourcepub async fn extract_snapshot(
&self,
archive_path: &Path,
target_dir: &Path,
) -> SnapshotResult<Vec<String>>
pub async fn extract_snapshot( &self, archive_path: &Path, target_dir: &Path, ) -> SnapshotResult<Vec<String>>
Extracts a tar.xz snapshot archive safely to the target directory.
Validates each file path to prevent directory traversal attacks and only extracts expected database files.
§Arguments
archive_path- Path to the tar.xz archive filetarget_dir- Directory where files will be extracted
§Returns
Vector of successfully extracted file names (relative paths)
§Errors
SnapshotError::Archive- Invalid archive format or extraction failureSnapshotError::Io- File system errors during extractionSnapshotError::InvalidFormat- Path traversal attempt detected
§Security
This method validates all file paths to prevent extraction outside the target directory (path traversal attacks).
Sourcepub async fn validate_archive(
&self,
archive_path: &Path,
) -> SnapshotResult<Vec<String>>
pub async fn validate_archive( &self, archive_path: &Path, ) -> SnapshotResult<Vec<String>>
Validates that the archive contains expected files without extracting
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SnapshotExtractor
impl RefUnwindSafe for SnapshotExtractor
impl Send for SnapshotExtractor
impl Sync for SnapshotExtractor
impl Unpin for SnapshotExtractor
impl UnwindSafe for SnapshotExtractor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more