src/backup/backup_info.rs: new helper to list files

This commit is contained in:
Dietmar Maurer 2019-03-06 10:49:01 +01:00
parent dd79265a8a
commit 58e99e138e
2 changed files with 22 additions and 2 deletions

View File

@ -157,10 +157,25 @@ impl BackupInfo {
} }
} }
pub fn list_backups(path: &Path) -> Result<Vec<BackupInfo>, Error> { pub fn list_files(base_path: &Path, backup_dir: &BackupDir) -> Result<Vec<String>, Error> {
let mut path = base_path.to_owned();
path.push(backup_dir.relative_path());
let mut files = vec![];
tools::scandir(libc::AT_FDCWD, &path, &BACKUP_FILE_REGEX, |_, filename, file_type| {
if file_type != nix::dir::Type::File { return Ok(()); }
files.push(filename.to_owned());
Ok(())
})?;
Ok(files)
}
pub fn list_backups(base_path: &Path) -> Result<Vec<BackupInfo>, Error> {
let mut list = vec![]; let mut list = vec![];
tools::scandir(libc::AT_FDCWD, path, &BACKUP_TYPE_REGEX, |l0_fd, backup_type, file_type| { 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(()); } if file_type != nix::dir::Type::Directory { return Ok(()); }
tools::scandir(l0_fd, backup_type, &BACKUP_ID_REGEX, |l1_fd, backup_id, file_type| { tools::scandir(l0_fd, backup_type, &BACKUP_ID_REGEX, |l1_fd, backup_id, file_type| {
if file_type != nix::dir::Type::Directory { return Ok(()); } if file_type != nix::dir::Type::Directory { return Ok(()); }

View File

@ -168,6 +168,11 @@ impl DataStore {
BackupInfo::list_backups(&path) BackupInfo::list_backups(&path)
} }
pub fn list_files(&self, backup_dir: &BackupDir) -> Result<Vec<String>, Error> {
let path = self.base_path();
BackupInfo::list_files(&path, backup_dir)
}
pub fn list_images(&self) -> Result<Vec<PathBuf>, Error> { pub fn list_images(&self) -> Result<Vec<PathBuf>, Error> {
let base = self.base_path(); let base = self.base_path();