-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move getting snapshots to rustic_core
- Loading branch information
Showing
8 changed files
with
69 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod cat; | |
pub mod check; | ||
pub mod prune; | ||
pub mod repoinfo; | ||
pub mod snapshots; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! `smapshot` subcommand | ||
|
||
use crate::{ | ||
OpenRepository, ProgressBars, RusticResult, SnapshotFile, SnapshotGroup, SnapshotGroupCriterion, | ||
}; | ||
|
||
pub(crate) fn get_snapshot_group<P: ProgressBars>( | ||
repo: &OpenRepository<P>, | ||
ids: &[String], | ||
group_by: SnapshotGroupCriterion, | ||
filter: impl FnMut(&SnapshotFile) -> bool, | ||
) -> RusticResult<Vec<(SnapshotGroup, Vec<SnapshotFile>)>> { | ||
let pb = &repo.pb; | ||
let p = pb.progress_counter("getting snapshots..."); | ||
let groups = match ids { | ||
[] => SnapshotFile::group_from_backend(&repo.dbe, filter, group_by, &p)?, | ||
[id] if id == "latest" => { | ||
SnapshotFile::group_from_backend(&repo.dbe, filter, group_by, &p)? | ||
.into_iter() | ||
.map(|(group, mut snaps)| { | ||
snaps.sort_unstable(); | ||
let last_idx = snaps.len() - 1; | ||
snaps.swap(0, last_idx); | ||
snaps.truncate(1); | ||
(group, snaps) | ||
}) | ||
.collect::<Vec<_>>() | ||
} | ||
_ => { | ||
let item = ( | ||
SnapshotGroup::default(), | ||
SnapshotFile::from_ids(&repo.dbe, ids, &p)?, | ||
); | ||
vec![item] | ||
} | ||
}; | ||
|
||
Ok(groups) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters