src/backup/datastore.rs: add helper to sort backup lists

This commit is contained in:
Dietmar Maurer
2019-03-04 18:20:57 +01:00
parent 875fb1c01a
commit 2b01a22507
2 changed files with 15 additions and 5 deletions

View File

@ -131,6 +131,16 @@ pub struct BackupInfo {
pub files: Vec<String>,
}
impl BackupInfo {
pub fn sort_list(list: &mut Vec<BackupInfo>, ascendending: bool) {
if ascendending { // oldest first
list.sort_unstable_by(|a, b| a.backup_dir.backup_time.cmp(&b.backup_dir.backup_time));
} else { // newest first
list.sort_unstable_by(|a, b| b.backup_dir.backup_time.cmp(&a.backup_dir.backup_time));
}
}
}
macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9][A-Za-z0-9_-]+") }
macro_rules! BACKUP_TYPE_RE { () => (r"(?:host|vm|ct)") }