use crate::utils::{archive, archive::FileEntryDef, setup};
use clap::Parser;
use portable_network_archive::cli;
const ENTRY_PATH: &str = "test.txt";
const ENTRY_CONTENT: &[u8] = b"test content";
#[test]
fn chmod_numeric_mode() {
setup();
archive::create_archive_with_permissions(
"chmod_numeric.pna",
&[FileEntryDef {
path: ENTRY_PATH,
content: ENTRY_CONTENT,
permission: 0o777,
}],
)
.unwrap();
cli::Cli::try_parse_from([
"pna",
"--quiet",
"experimental",
"chmod",
"-f",
"chmod_numeric.pna",
"644",
ENTRY_PATH,
])
.unwrap()
.execute()
.unwrap();
let mut found = false;
archive::for_each_entry("chmod_numeric.pna", |entry| {
if entry.header().path() == ENTRY_PATH {
found = true;
let mode = entry
.metadata()
.permission_mode()
.expect("entry should have permission mode metadata")
.get();
assert_eq!(mode & 0o777, 0o644, "644 on 0o777 should yield 0o644");
}
})
.unwrap();
assert!(found, "target entry not found in archive");
}