Skip to content

Commit 6453bc3

Browse files
committed
💥 Fail stdio create when no input paths are given
Previously `pna experimental stdio -c -f out.pna` with no positional arguments silently created an empty archive. Bail with an actionable error message, matching bsdtar behavior.
1 parent d08ecba commit 6453bc3

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

cli/src/command/stdio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,9 @@ fn run_create_archive(args: StdioCommand) -> anyhow::Result<()> {
850850
if let Some(path) = args.files_from {
851851
files.extend(read_paths(path, args.null)?);
852852
}
853+
if files.is_empty() {
854+
anyhow::bail!("create mode requires at least one input path or @archive source");
855+
}
853856

854857
let mut exclude = args.exclude;
855858
if let Some(p) = args.exclude_from {

cli/tests/cli/stdio.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod archive_inclusion;
22
mod exclude_vcs;
33
mod files_from;
4+
mod missing_file;
45
#[cfg(unix)]
56
mod mtree;
67
mod option_auto_compress;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::utils::setup;
2+
use assert_cmd::cargo::cargo_bin_cmd;
3+
4+
/// Precondition: No input paths are provided.
5+
/// Action: Run `pna experimental stdio -c -f ...` without positional paths.
6+
/// Expectation: Command fails similarly to bsdtar's "missing file" handling.
7+
#[test]
8+
fn stdio_create_without_inputs_fails() {
9+
setup();
10+
11+
let mut cmd = cargo_bin_cmd!("pna");
12+
cmd.args([
13+
"--quiet",
14+
"experimental",
15+
"stdio",
16+
"--unstable",
17+
"-c",
18+
"-f",
19+
"stdio_create_without_inputs_fails.pna",
20+
]);
21+
cmd.assert().failure();
22+
}

0 commit comments

Comments
 (0)