No such backup/backup already esists

This commit is contained in:
Dennis Schwerdel 2017-04-09 18:48:38 +02:00 committed by Dennis Schwerdel
parent f5faa89c6a
commit cca4e76c3b
3 changed files with 17 additions and 2 deletions

View File

@ -10,7 +10,6 @@
* Lock the local repository to avoid index corruption
## Usability
* Error: Backup already exists
* Backup directories as a thing (list, remove)
* Display backup name and path on backup integrity error
* Better control over what is checked in `check` subcommand

View File

@ -20,6 +20,7 @@ pub enum ErrorCode {
InitializeLogger,
CreateRepository,
LoadRepository, SaveBackup, LoadBackup, LoadInode, LoadBundle,
NoSuchBackup, BackupAlreadyExists,
AddKey, LoadKey, SaveKey,
SaveConfig,
LoadExcludes, InvalidExcludes,
@ -58,7 +59,10 @@ impl ErrorCode {
ErrorCode::DiffRun => 21,
ErrorCode::VersionsRun => 22,
ErrorCode::ImportRun => 23,
ErrorCode::FuseMount => 24
ErrorCode::FuseMount => 24,
//
ErrorCode::NoSuchBackup => 25,
ErrorCode::BackupAlreadyExists => 26
}
}
}
@ -92,6 +96,10 @@ fn open_repository(path: &str) -> Result<Repository, ErrorCode> {
}
fn get_backup(repo: &Repository, backup_name: &str) -> Result<Backup, ErrorCode> {
if !repo.has_backup(backup_name) {
error!("A backup with that name does not exist");
return Err(ErrorCode::NoSuchBackup)
}
Ok(checked!(repo.get_backup(backup_name), "load backup", ErrorCode::LoadBackup))
}
@ -286,6 +294,10 @@ pub fn run() -> Result<(), ErrorCode> {
},
Arguments::Backup{repo_path, backup_name, src_path, full, reference, same_device, mut excludes, excludes_from, no_default_excludes, tar} => {
let mut repo = try!(open_repository(&repo_path));
if repo.has_backup(&backup_name) {
error!("A backup with that name already exists");
return Err(ErrorCode::BackupAlreadyExists)
}
let mut reference_backup = None;
if !full && !tar {
reference_backup = match reference {

View File

@ -41,6 +41,10 @@ impl Repository {
Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path())))
}
pub fn has_backup(&self, name: &str) -> bool {
self.layout.backup_path(name).exists()
}
pub fn get_backup(&self, name: &str) -> Result<Backup, RepositoryError> {
Ok(try!(Backup::read_from(&self.crypto.lock().unwrap(), self.layout.backup_path(name))))
}