refactor(backup): delta contributions function no longer takes reversed input
parent
5f43d7b8b1
commit
f2a0b6230f
|
@ -110,20 +110,19 @@ impl Delta {
|
|||
out
|
||||
}
|
||||
|
||||
/// Given a chain of deltas, ordered from last to first, calculate the "contribution" for each
|
||||
/// state.
|
||||
/// Given a chain of deltas, calculate the "contribution" for each state.
|
||||
///
|
||||
/// The contribution of a delta in a given chain is defined as the parts of the state produced
|
||||
/// by this chain that are actually provided by this delta. This comes down to calculating the
|
||||
/// strict difference of this delta and all of its successive deltas.
|
||||
/// For each delta, its contribution is the part of its added and removed files that isn't
|
||||
/// overwritten by any of its following deltas.
|
||||
pub fn contributions<I>(deltas: I) -> Vec<State>
|
||||
where
|
||||
I: IntoIterator,
|
||||
I::IntoIter: DoubleEndedIterator,
|
||||
I::Item: Borrow<Delta>,
|
||||
{
|
||||
let mut contributions: Vec<State> = Vec::new();
|
||||
|
||||
let mut deltas = deltas.into_iter();
|
||||
let mut deltas = deltas.into_iter().rev();
|
||||
|
||||
if let Some(first_delta) = deltas.next() {
|
||||
// From last to first, we calculate the strict difference of the delta with the union of all its
|
||||
|
@ -138,8 +137,7 @@ impl Delta {
|
|||
}
|
||||
}
|
||||
|
||||
// contributions.reverse();
|
||||
|
||||
contributions.reverse();
|
||||
contributions
|
||||
}
|
||||
|
||||
|
@ -286,12 +284,12 @@ mod tests {
|
|||
.with_removed("dir2", ["file3"]),
|
||||
];
|
||||
let expected = [
|
||||
State::default().with_dir("dir1", ["file2"]),
|
||||
State::default().with_dir("dir1", ["file1"]),
|
||||
State::default(),
|
||||
State::default().with_dir("dir1", ["file4"]),
|
||||
State::default(),
|
||||
State::default().with_dir("dir1", ["file1"]),
|
||||
State::default().with_dir("dir1", ["file2"]),
|
||||
];
|
||||
|
||||
assert_eq!(Delta::contributions(deltas.iter().rev()), expected);
|
||||
assert_eq!(Delta::contributions(deltas), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,9 +229,8 @@ where
|
|||
.map(|_| ()),
|
||||
// Incremental backups are exported one by one according to their contribution
|
||||
BackupType::Incremental => {
|
||||
let contributions = Delta::contributions(
|
||||
chain.iter().take(index + 1).map(|b| &b.delta).rev(),
|
||||
);
|
||||
let contributions =
|
||||
Delta::contributions(chain.iter().take(index + 1).map(|b| &b.delta));
|
||||
|
||||
let tar_gz = OpenOptions::new()
|
||||
.write(true)
|
||||
|
@ -245,7 +244,6 @@ where
|
|||
// overwritten by their successors anyways.
|
||||
for (contribution, backup) in contributions
|
||||
.iter()
|
||||
.rev()
|
||||
.zip(chain.iter().take(index + 1))
|
||||
.filter(|(contribution, _)| !contribution.is_empty())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue