use super::{builder::PackBuilder, cmd::execute_rfs_command, error::RfsError, types::StoreSpec};
pub fn pack_directory(
directory: &str,
output: &str,
store_specs: &[StoreSpec],
) -> Result<(), RfsError> {
let mut builder = PackBuilder::new(directory, output);
for spec in store_specs {
builder = builder.with_store_spec(spec.clone());
}
builder.pack()
}
pub fn unpack(input: &str, directory: &str) -> Result<(), RfsError> {
let result = execute_rfs_command(&["unpack", "-m", input, directory])?;
if !result.success {
return Err(RfsError::Other(format!(
"Failed to unpack {}: {}",
input, result.stderr
)));
}
Ok(())
}
pub fn list_contents(input: &str) -> Result<String, RfsError> {
let result = execute_rfs_command(&["list", "-m", input])?;
if !result.success {
return Err(RfsError::Other(format!(
"Failed to list contents of {}: {}",
input, result.stderr
)));
}
Ok(result.stdout)
}
pub fn verify(input: &str) -> Result<bool, RfsError> {
let result = execute_rfs_command(&["verify", "-m", input])?;
if !result.success {
if result.stderr.contains("verification failed") {
return Ok(false);
}
return Err(RfsError::Other(format!(
"Failed to verify {}: {}",
input, result.stderr
)));
}
Ok(true)
}