Merge pull request #30 from BBareth/codex/rpf-probe-option-conflicts

This commit is contained in:
ivall
2026-11-22 13:51:48 +01:00
3 changed files with 44 additions and 5 deletions
+1
View File
@@ -37,6 +37,7 @@ Usage:
xcl rpf <package.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
";
+8 -5
View File
@@ -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");
+35
View File
@@ -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]));
}
}