feat: don't read non-contributing archives for export

main
Jef Roosens 2023-07-08 14:50:18 +02:00
parent b924a054a6
commit 6cdc18742e
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 31 additions and 4 deletions

View File

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://git.rustybever.be/Chewing_Bever/alex/src/branch/dev) ## [Unreleased](https://git.rustybever.be/Chewing_Bever/alex/src/branch/dev)
### Changed
* Export command no longer reads backups that do not contribute to the final
state
## [0.3.1](https://git.rustybever.be/Chewing_Bever/alex/src/tag/0.3.1) ## [0.3.1](https://git.rustybever.be/Chewing_Bever/alex/src/tag/0.3.1)
### Added ### Added

View File

@ -18,11 +18,18 @@ pub struct Delta {
impl Delta { impl Delta {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
added: Default::default(), added: State::new(),
removed: Default::default(), removed: State::new(),
} }
} }
/// Returns whether the delta is empty by checking whether both its added and removed state
/// return true for their `is_empty`.
#[allow(dead_code)]
pub fn is_empty(&self) -> bool {
self.added.is_empty() && self.removed.is_empty()
}
/// Calculate the union of this delta with another delta. /// Calculate the union of this delta with another delta.
/// ///
/// The union of two deltas is a delta that produces the same state as if you were to apply /// The union of two deltas is a delta that produces the same state as if you were to apply

View File

@ -226,9 +226,16 @@ where
let enc = GzEncoder::new(tar_gz, Compression::default()); let enc = GzEncoder::new(tar_gz, Compression::default());
let mut ar = tar::Builder::new(enc); let mut ar = tar::Builder::new(enc);
for (contribution, backup) in // We only need to consider backups that have a non-empty contribution.
contributions.iter().rev().zip(chain.iter().take(index + 1)) // This allows us to skip reading backups that have been completely
// overwritten by their successors anyways.
for (contribution, backup) in contributions
.iter()
.rev()
.zip(chain.iter().take(index + 1))
.filter(|(contribution, _)| !contribution.is_empty())
{ {
println!("{}", &backup);
backup.append(&self.backup_dir, contribution, &mut ar)?; backup.append(&self.backup_dir, contribution, &mut ar)?;
} }

View File

@ -41,6 +41,14 @@ impl State {
path.starts_with(dir) && files.contains(path.strip_prefix(dir).unwrap()) path.starts_with(dir) && files.contains(path.strip_prefix(dir).unwrap())
}) })
} }
/// Returns whether the state is empty.
///
/// Note that this does not necessarily mean that the state does not contain any sets, but
/// rather that any sets that it does contain are also empty.
pub fn is_empty(&self) -> bool {
self.0.values().all(|s| s.is_empty())
}
} }
impl<T> From<T> for State impl<T> From<T> for State