diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1fe35..51183dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/cli/args.rs b/src/cli/args.rs index 72b70d4..dad2cb9 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -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(" 'Source path to backup'") - .validator(validate_existing_path)) + .validator(validate_existing_path_or_stdio)) .arg(Arg::from_usage(" '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") diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 9961e12..f2825c4 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -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 {