From 108764f95b255159ce901582c72d6b885608c8cb Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Mon, 3 Jun 2024 16:37:16 +0200 Subject: [PATCH] pxar: bin: support creation of split pxar archives via cli Add support to create split pxar archives by redirecting the payload output to a dedicated file. Signed-off-by: Christian Ebner --- pxar-bin/src/main.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 7ea5b114..638ac00b 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -328,6 +328,10 @@ fn extract_archive( minimum: 0, maximum: isize::MAX, }, + "payload-output": { + description: "'ppxar' payload output data file to create split archive.", + optional: true, + }, }, }, )] @@ -345,6 +349,7 @@ async fn create_archive( no_sockets: bool, exclude: Option>, entries_max: isize, + payload_output: Option, ) -> Result<(), Error> { let patterns = { let input = exclude.unwrap_or_default(); @@ -387,6 +392,16 @@ async fn create_archive( .mode(0o640) .open(archive)?; + let payload_file = payload_output + .map(|payload_output| { + OpenOptions::new() + .create_new(true) + .write(true) + .mode(0o640) + .open(payload_output) + }) + .transpose()?; + let writer = std::io::BufWriter::with_capacity(1024 * 1024, file); let mut feature_flags = Flags::DEFAULT; if no_xattrs { @@ -408,7 +423,15 @@ async fn create_archive( feature_flags.remove(Flags::WITH_SOCKETS); } - let writer = pxar::PxarVariant::Unified(pxar::encoder::sync::StandardWriter::new(writer)); + let writer = if let Some(payload_file) = payload_file { + let payload_writer = std::io::BufWriter::with_capacity(1024 * 1024, payload_file); + pxar::PxarVariant::Split( + pxar::encoder::sync::StandardWriter::new(writer), + pxar::encoder::sync::StandardWriter::new(payload_writer), + ) + } else { + pxar::PxarVariant::Unified(pxar::encoder::sync::StandardWriter::new(writer)) + }; pbs_client::pxar::create_archive( dir, PxarWriters::new(writer, None), @@ -535,7 +558,8 @@ fn main() { CliCommand::new(&API_METHOD_CREATE_ARCHIVE) .arg_param(&["archive", "source"]) .completion_cb("archive", complete_file_name) - .completion_cb("source", complete_file_name), + .completion_cb("source", complete_file_name) + .completion_cb("payload-output", complete_file_name), ) .insert( "extract",