Fixed reading tar files from stdin

pull/10/head
Dennis Schwerdel 2017-05-11 09:45:55 +02:00
parent 1cd58e180d
commit 30bc7d80c5
3 changed files with 15 additions and 1 deletions

View File

@ -6,6 +6,7 @@ This project follows [semantic versioning](http://semver.org).
### UNRELEASED
* [modifed] Changed order of arguments in `addkey` to match src-dst scheme
* [fixed] Fixed `addkey` subcommand
* [fixed] Fixed reading tar files from stdin
### v0.3.1 (2017-05-09)

View File

@ -279,6 +279,15 @@ fn validate_existing_path(val: String) -> Result<(), String> {
}
}
#[allow(unknown_lints,needless_pass_by_value)]
fn validate_existing_path_or_stdio(val: String) -> Result<(), String> {
if val != "-" && !Path::new(&val).exists() {
Err("Path does not exist".to_string())
} else {
Ok(())
}
}
#[allow(unknown_lints,cyclomatic_complexity)]
pub fn parse() -> Result<(LogLevel, Arguments), ErrorCode> {
@ -312,7 +321,7 @@ pub fn parse() -> Result<(LogLevel, Arguments), ErrorCode> {
.arg(Arg::from_usage("--tar 'Read the source data from a tar file'")
.conflicts_with_all(&["reference", "exclude", "excludes_from"]))
.arg(Arg::from_usage("<SRC> 'Source path to backup'")
.validator(validate_existing_path))
.validator(validate_existing_path_or_stdio))
.arg(Arg::from_usage("<BACKUP> 'Backup path, [repository]::backup'")
.validator(|val| validate_repo_path(val, true, Some(true), Some(false)))))
.subcommand(SubCommand::with_name("restore").about("Restore a backup or subtree")

View File

@ -313,6 +313,10 @@ pub fn run() -> Result<(), ErrorCode> {
error!("A backup with that name already exists");
return Err(ErrorCode::BackupAlreadyExists)
}
if src_path == "-" && !tar {
error!("Reading from stdin requires --tar");
return Err(ErrorCode::InvalidArgs)
}
let mut reference_backup = None;
if !full && !tar {
reference_backup = match reference {