feat(rust-core): add zstd chunk compression support and rewrite partially referenced packs during prune
This commit is contained in:
@@ -10,7 +10,7 @@ use crate::encryption;
|
||||
use crate::error::ArchiveError;
|
||||
use crate::hasher;
|
||||
use crate::pack_reader;
|
||||
use crate::pack_writer::IdxEntry;
|
||||
use crate::pack_writer::{IdxEntry, FLAG_ENCRYPTED};
|
||||
use crate::repository::Repository;
|
||||
use crate::snapshot;
|
||||
|
||||
@@ -76,8 +76,15 @@ pub async fn restore(
|
||||
index_entry.compressed_size,
|
||||
).await?;
|
||||
|
||||
// Get flags for this chunk (determines compression algorithm)
|
||||
let chunk_flags = index_entry.flags;
|
||||
|
||||
// Decrypt if encrypted
|
||||
let compressed = if let Some(ref key) = repo.master_key {
|
||||
let compressed = if chunk_flags & FLAG_ENCRYPTED != 0 {
|
||||
let key = repo.master_key.as_ref().ok_or_else(|| {
|
||||
ArchiveError::Encryption("Chunk is encrypted but no key available".to_string())
|
||||
})?;
|
||||
|
||||
// Try to get nonce from the global index first (fast path)
|
||||
let nonce = if let Some(ref nonce_hex) = index_entry.nonce {
|
||||
let nonce_bytes = hex::decode(nonce_hex)
|
||||
@@ -117,8 +124,8 @@ pub async fn restore(
|
||||
stored_data
|
||||
};
|
||||
|
||||
// Decompress
|
||||
let plaintext = compression::decompress(&compressed)?;
|
||||
// Decompress using flags to determine algorithm
|
||||
let plaintext = compression::decompress_by_flags(&compressed, chunk_flags)?;
|
||||
|
||||
// Verify hash
|
||||
let actual_hash = hasher::hash_chunk(&plaintext);
|
||||
|
||||
Reference in New Issue
Block a user