diff --git a/src/bin/pxar.rs b/src/bin/pxar.rs index 0ddbdac2..8e8064bb 100644 --- a/src/bin/pxar.rs +++ b/src/bin/pxar.rs @@ -12,8 +12,7 @@ use serde_json::{Value}; use std::io::Write; use std::path::{Path, PathBuf}; -use proxmox_backup::pxar::encoder::*; -use proxmox_backup::pxar::decoder::*; +use proxmox_backup::pxar; fn print_filenames( param: Value, @@ -26,7 +25,7 @@ fn print_filenames( let mut reader = std::io::BufReader::new(file); - let mut decoder = PxarDecoder::new(&mut reader); + let mut decoder = pxar::SequentialDecoder::new(&mut reader); let stdout = std::io::stdout(); let mut out = stdout.lock(); @@ -48,7 +47,7 @@ fn dump_archive( let mut reader = std::io::BufReader::new(file); - let mut decoder = PxarDecoder::new(&mut reader); + let mut decoder = pxar::SequentialDecoder::new(&mut reader); let stdout = std::io::stdout(); let mut out = stdout.lock(); @@ -75,7 +74,7 @@ fn extract_archive( let mut reader = std::io::BufReader::new(file); - let mut decoder = PxarDecoder::new(&mut reader); + let mut decoder = pxar::SequentialDecoder::new(&mut reader); decoder.restore(Path::new(target), & |path| { if verbose { @@ -110,7 +109,7 @@ fn create_archive( let mut writer = std::io::BufWriter::with_capacity(1024*1024, file); - PxarEncoder::encode(source, &mut dir, &mut writer, all_file_systems, verbose)?; + pxar::Encoder::encode(source, &mut dir, &mut writer, all_file_systems, verbose)?; writer.flush()?; diff --git a/src/client/pxar_backup_stream.rs b/src/client/pxar_backup_stream.rs index 48ca6e94..9b3246db 100644 --- a/src/client/pxar_backup_stream.rs +++ b/src/client/pxar_backup_stream.rs @@ -11,7 +11,7 @@ use nix::fcntl::OFlag; use nix::sys::stat::Mode; use nix::dir::Dir; -use crate::pxar::encoder::*; +use crate::pxar; /// Stream implementation to encode and upload .pxar archives. /// @@ -44,7 +44,7 @@ impl PxarBackupStream { let child = thread::spawn(move|| { let mut writer = unsafe { std::fs::File::from_raw_fd(tx) }; - if let Err(err) = PxarEncoder::encode(path, &mut dir, &mut writer, all_file_systems, verbose) { + if let Err(err) = pxar::Encoder::encode(path, &mut dir, &mut writer, all_file_systems, verbose) { eprintln!("pxar encode failed - {}", err); } }); diff --git a/src/client/pxar_decode_writer.rs b/src/client/pxar_decode_writer.rs index 968b3f6d..4c3a6f60 100644 --- a/src/client/pxar_decode_writer.rs +++ b/src/client/pxar_decode_writer.rs @@ -5,7 +5,7 @@ use std::os::unix::io::FromRawFd; use std::path::{Path, PathBuf}; use std::io::Write; -use crate::pxar::decoder::*; +use crate::pxar; /// Writer implementation to deccode a .pxar archive (download). @@ -31,7 +31,7 @@ impl PxarDecodeWriter { let child = thread::spawn(move|| { let mut reader = unsafe { std::fs::File::from_raw_fd(rx) }; - let mut decoder = PxarDecoder::new(&mut reader); + let mut decoder = pxar::SequentialDecoder::new(&mut reader); if let Err(err) = decoder.restore(&base, & |path| { if verbose { diff --git a/src/pxar.rs b/src/pxar.rs index 91d79df6..be5f2e72 100644 --- a/src/pxar.rs +++ b/src/pxar.rs @@ -38,8 +38,13 @@ //! * ... //! * GOODBYE -- lookup table at the end of a list of directory entries -pub mod binary_search_tree; -pub mod format_definition; -pub mod encoder; -pub mod decoder; +mod binary_search_tree; +mod format_definition; +pub use format_definition::*; + +mod encoder; +pub use encoder::*; + +mod decoder; +pub use decoder::*; diff --git a/src/pxar/decoder.rs b/src/pxar/decoder.rs index af8084f2..c3330f06 100644 --- a/src/pxar/decoder.rs +++ b/src/pxar/decoder.rs @@ -22,14 +22,14 @@ use nix::errno::Errno; use nix::NixPath; // This one need Read, but works without Seek -pub struct PxarDecoder<'a, R: Read> { +pub struct SequentialDecoder<'a, R: Read> { reader: &'a mut R, skip_buffer: Vec, } const HEADER_SIZE: u64 = std::mem::size_of::() as u64; -impl <'a, R: Read> PxarDecoder<'a, R> { +impl <'a, R: Read> SequentialDecoder<'a, R> { pub fn new(reader: &'a mut R) -> Self { let skip_buffer = vec![0u8; 64*1024]; diff --git a/src/pxar/encoder.rs b/src/pxar/encoder.rs index 1a15df0f..7baadc01 100644 --- a/src/pxar/encoder.rs +++ b/src/pxar/encoder.rs @@ -27,7 +27,7 @@ use nix::sys::stat::FileStat; /// maximum memory usage. pub const MAX_DIRECTORY_ENTRIES: usize = 256*1024; -pub struct PxarEncoder<'a, W: Write> { +pub struct Encoder<'a, W: Write> { current_path: PathBuf, // used for error reporting writer: &'a mut W, writer_pos: usize, @@ -38,7 +38,7 @@ pub struct PxarEncoder<'a, W: Write> { verbose: bool, } -impl <'a, W: Write> PxarEncoder<'a, W> { +impl <'a, W: Write> Encoder<'a, W> { pub fn encode( path: PathBuf,