Verified Commit 8da55aab authored by Jeremy Soller's avatar Jeremy Soller
Browse files

0.1.8 - add output paths to pkgar split command

parent 2f79cd0d
[package]
name = "pkgar"
version = "0.1.7"
version = "0.1.8"
description = "Redox Package Archive"
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>", "Wesley Hershberger <mggmugginsmc@gmail.com>"]
......
......@@ -251,6 +251,8 @@ pub fn list(
pub fn split(
pkey_path: impl AsRef<Path>,
archive_path: impl AsRef<Path>,
head_path: impl AsRef<Path>,
data_path_opt: Option<impl AsRef<Path>>,
) -> Result<(), Error> {
let pkey = PublicKeyFile::open(&pkey_path.as_ref())?.pkey;
......@@ -258,36 +260,34 @@ pub fn split(
let data_offset = package.header().total_size()?;
let mut src = package.src.into_inner();
{
let data_path = archive_path.as_ref().with_extension("pkgar_data");
if let Some(data_path) = data_path_opt {
let mut data_file = fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(&data_path)
.chain_err(|| &data_path )?;
.chain_err(|| data_path.as_ref() )?;
src.seek(SeekFrom::Start(data_offset))
.chain_err(|| archive_path.as_ref())?;
io::copy(&mut src, &mut data_file)
.chain_err(|| archive_path.as_ref())
.chain_err(|| &data_path)?;
.chain_err(|| data_path.as_ref())?;
}
{
let head_path = archive_path.as_ref().with_extension("pkgar_head");
let mut head_file = fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(&head_path)
.chain_err(|| &head_path )?;
.chain_err(|| head_path.as_ref() )?;
src.seek(SeekFrom::Start(0))
.chain_err(|| archive_path.as_ref())?;
io::copy(&mut src.take(data_offset), &mut head_file)
.chain_err(|| archive_path.as_ref())
.chain_err(|| &head_path)?;
.chain_err(|| head_path.as_ref())?;
}
Ok(())
......
......@@ -84,6 +84,17 @@ fn main() {
.about("Split archive into head and data files")
.arg(&arg_pkey)
.arg(&arg_archive)
.arg(
Arg::with_name("head")
.help("Header file")
.required(true)
.value_name("head")
)
.arg(
Arg::with_name("data")
.help("Data file")
.value_name("data")
)
)
.get_matches();
......@@ -113,7 +124,9 @@ fn main() {
} else if let Some(matches) = matches.subcommand_matches("split") {
split(
matches.value_of("pkey").unwrap(),
matches.value_of("archive").unwrap()
matches.value_of("archive").unwrap(),
matches.value_of("head").unwrap(),
matches.value_of("data")
)
} else {
Ok(())
......
......@@ -35,7 +35,14 @@ time target/$build/pkgar \
time target/$build/pkgar \
split \
--pkey target/test/public.toml \
--archive target/test/src.pkgar
--archive target/test/src.pkgar \
target/test/src.pkgar_head \
target/test/src.pkgar_data
time target/$build/pkgar \
list \
--pkey target/test/public.toml \
--archive target/test/src.pkgar_head
time target/$build/pkgar \
extract \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment