src/backup/backup_info.rs: new list_groups helper

This commit is contained in:
Dietmar Maurer 2020-01-17 10:39:32 +01:00
parent b31c8019d7
commit 11d89239c3

View File

@ -37,7 +37,7 @@ lazy_static!{
}
/// BackupGroup is a directory containing a list of BackupDir
#[derive(Debug, Clone)]
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
pub struct BackupGroup {
/// Type of backup
backup_type: String,
@ -137,6 +137,19 @@ impl BackupGroup {
Ok(last)
}
pub fn list_groups(base_path: &Path) -> Result<Vec<BackupGroup>, Error> {
let mut list = Vec::new();
tools::scandir(libc::AT_FDCWD, base_path, &BACKUP_TYPE_REGEX, |l0_fd, backup_type, file_type| {
if file_type != nix::dir::Type::Directory { return Ok(()); }
tools::scandir(l0_fd, backup_type, &BACKUP_ID_REGEX, |_l1_fd, backup_id, file_type| {
if file_type != nix::dir::Type::Directory { return Ok(()); }
list.push(BackupGroup::new(backup_type, backup_id));
Ok(())
})
})?;
Ok(list)
}
}
/// Uniquely identify a Backup (relative to data store)
@ -249,7 +262,7 @@ impl BackupInfo {
}
pub fn list_backups(base_path: &Path) -> Result<Vec<BackupInfo>, Error> {
let mut list = vec![];
let mut list = Vec::new();
tools::scandir(libc::AT_FDCWD, base_path, &BACKUP_TYPE_REGEX, |l0_fd, backup_type, file_type| {
if file_type != nix::dir::Type::Directory { return Ok(()); }