diff --git a/crates/xcl/src/main.rs b/crates/xcl/src/main.rs index bd231ba..f154f21 100644 --- a/crates/xcl/src/main.rs +++ b/crates/xcl/src/main.rs @@ -37,6 +37,7 @@ Usage: xcl rpf [--top N] [--find NAME] [--extract NAME --out DIR] Lists or extracts readable inline records. Archives larger than 1 GB use a bounded-memory header probe; --probe requests it explicitly and --full overrides it. + Use --probe only for header summaries, without --find, --extract, --out or --full. xcl --version "; diff --git a/crates/xcl/src/rpf.rs b/crates/xcl/src/rpf.rs index d8f2a2e..d723803 100644 --- a/crates/xcl/src/rpf.rs +++ b/crates/xcl/src/rpf.rs @@ -99,6 +99,14 @@ fn atomic_write(path: &Path, data: &[u8]) -> io::Result<()> { pub fn run(path: &Path, args: &[String]) -> i32 { let opt = |n: &str| args.iter().position(|a| a == n).and_then(|i| args.get(i + 1)).cloned(); let top: usize = opt("--top").and_then(|v| v.parse().ok()).unwrap_or(30); + let force_full = args.iter().any(|arg| arg == "--full"); + if args.iter().any(|arg| arg == "--probe") { + if let Some(conflict) = args.iter().find(|arg| matches!(arg.as_str(), "--full" | "--find" | "--extract" | "--out")) { + eprintln!("xcl rpf: --probe cannot be combined with {conflict}"); + return 2; + } + return crate::rpf_probe::run(path, top); + } let find = opt("--find"); let extract = opt("--extract"); let out = opt("--out").map(PathBuf::from).unwrap_or_else(|| PathBuf::from("rpf_out")); @@ -109,11 +117,6 @@ pub fn run(path: &Path, args: &[String]) -> i32 { return 2; } }; - let explicit_probe = args.iter().any(|arg| arg == "--probe"); - let force_full = args.iter().any(|arg| arg == "--full"); - if explicit_probe { - return crate::rpf_probe::run(path, top); - } if len > AUTO_PROBE_SIZE && !force_full { if find.is_some() || extract.is_some() { eprintln!("xcl rpf: detailed options on archives larger than 1 GB require --full"); diff --git a/crates/xcl/tests/rpf_e2e.rs b/crates/xcl/tests/rpf_e2e.rs index b875b53..ed7a4c0 100644 --- a/crates/xcl/tests/rpf_e2e.rs +++ b/crates/xcl/tests/rpf_e2e.rs @@ -39,3 +39,38 @@ fn full_scan_and_streaming_probe_agree_on_header_evidence() { assert!(full.contains("RPF9 archives (headers every 2 KB): 2")); assert!(full.contains("TOC encryption: unknown")); } + +#[test] +fn explicit_probe_rejects_conflicting_options() { + let nonce = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_nanos(); + let archive = std::env::temp_dir().join(format!( + "xcl-rpf-options-{}-{nonce}.rpf", + std::process::id() + )); + std::fs::write(&archive, b"9FPR").unwrap(); + + let options: [&[&str]; 4] = [ + &["--full"], + &["--find", "record"], + &["--extract", "record"], + &["--out", "unused"], + ]; + let outputs = options.map(|args| { + Command::new(env!("CARGO_BIN_EXE_xcl")) + .arg("rpf") + .arg(&archive) + .arg("--probe") + .args(args) + .output() + }); + std::fs::remove_file(&archive).unwrap(); + + for (args, output) in options.into_iter().zip(outputs) { + let output = output.unwrap(); + assert_eq!(output.status.code(), Some(2), "{args:?}: {output:?}"); + assert!(String::from_utf8(output.stderr).unwrap().contains(args[0])); + } +}