From 8968258b66fbec5bb272d399397d7aee14c17084 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 14 Mar 2019 10:54:09 +0100 Subject: [PATCH] rename catar into pxar To avoid confusion with the casync implementation. --- src/api2/admin/datastore.rs | 10 +++--- .../admin/datastore/{catar.rs => pxar.rs} | 32 +++++++++---------- src/api2/admin/datastore/upload.rs | 2 +- src/backup/dynamic_index.rs | 2 +- src/bin/proxmox-backup-client.rs | 22 +++++++------ src/bin/pxar.rs | 14 ++++---- src/client.rs | 8 ++--- ...backup_stream.rs => pxar_backup_stream.rs} | 18 +++++------ ...decode_writer.rs => pxar_decode_writer.rs} | 18 +++++------ src/lib.rs | 2 +- src/{catar.rs => pxar.rs} | 11 ++++--- src/{catar => pxar}/binary_search_tree.rs | 2 +- src/{catar => pxar}/decoder.rs | 8 ++--- src/{catar => pxar}/encoder.rs | 8 ++--- src/{catar => pxar}/format_definition.rs | 2 +- src/{catar => pxar}/inspector.rs | 8 ++--- 16 files changed, 85 insertions(+), 82 deletions(-) rename src/api2/admin/datastore/{catar.rs => pxar.rs} (88%) rename src/client/{catar_backup_stream.rs => pxar_backup_stream.rs} (83%) rename src/client/{catar_decode_writer.rs => pxar_decode_writer.rs} (75%) rename src/{catar.rs => pxar.rs} (85%) rename src/{catar => pxar}/binary_search_tree.rs (98%) rename src/{catar => pxar}/decoder.rs (98%) rename src/{catar => pxar}/encoder.rs (99%) rename src/{catar => pxar}/format_definition.rs (99%) rename src/{catar => pxar}/inspector.rs (99%) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 2ca52639..0e35dd42 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -17,7 +17,7 @@ use crate::config::datastore; use crate::backup::*; -mod catar; +mod pxar; mod upload; fn group_backups(backup_list: Vec) -> HashMap> { @@ -380,7 +380,7 @@ pub fn router() -> Router { .get(ApiMethod::new( |_,_,_| Ok(json!([ {"subdir": "backups" }, - {"subdir": "catar" }, + {"subdir": "pxar" }, {"subdir": "gc" }, {"subdir": "groups" }, {"subdir": "snapshots" }, @@ -398,10 +398,10 @@ pub fn router() -> Router { ObjectSchema::new("List backups.") .required("store", store_schema.clone())))) .subdir( - "catar", + "pxar", Router::new() - .download(catar::api_method_download_catar()) - .upload(catar::api_method_upload_catar())) + .download(pxar::api_method_download_pxar()) + .upload(pxar::api_method_upload_pxar())) .subdir( "test-upload", Router::new() diff --git a/src/api2/admin/datastore/catar.rs b/src/api2/admin/datastore/pxar.rs similarity index 88% rename from src/api2/admin/datastore/catar.rs rename to src/api2/admin/datastore/pxar.rs index 6e8e4b7d..225e4da0 100644 --- a/src/api2/admin/datastore/catar.rs +++ b/src/api2/admin/datastore/pxar.rs @@ -18,13 +18,13 @@ use std::sync::Arc; use hyper::Body; use hyper::http::request::Parts; -pub struct UploadCaTar { +pub struct UploadPxar { stream: Body, index: DynamicIndexWriter, count: usize, } -impl Future for UploadCaTar { +impl Future for UploadPxar { type Item = (); type Error = failure::Error; @@ -46,7 +46,7 @@ impl Future for UploadCaTar { } } -fn upload_catar( +fn upload_pxar( parts: Parts, req_body: Body, param: Value, @@ -57,8 +57,8 @@ fn upload_catar( let store = tools::required_string_param(¶m, "store")?; let mut archive_name = String::from(tools::required_string_param(¶m, "archive-name")?); - if !archive_name.ends_with(".catar") { - bail!("got wront file extension (expected '.catar')"); + if !archive_name.ends_with(".pxar") { + bail!("got wront file extension (expected '.pxar')"); } archive_name.push_str(".didx"); @@ -72,8 +72,8 @@ fn upload_catar( let content_type = parts.headers.get(http::header::CONTENT_TYPE) .ok_or(format_err!("missing content-type header"))?; - if content_type != "application/x-proxmox-backup-catar" { - bail!("got wrong content-type for catar archive upload"); + if content_type != "application/x-proxmox-backup-pxar" { + bail!("got wrong content-type for pxar archive upload"); } let chunk_size = param["chunk-size"].as_u64().unwrap_or(4096*1024); @@ -88,7 +88,7 @@ fn upload_catar( let index = datastore.create_dynamic_writer(path, chunk_size as usize)?; - let upload = UploadCaTar { stream: req_body, index, count: 0}; + let upload = UploadPxar { stream: req_body, index, count: 0}; let resp = upload.and_then(|_| { @@ -103,10 +103,10 @@ fn upload_catar( Ok(Box::new(resp)) } -pub fn api_method_upload_catar() -> ApiAsyncMethod { +pub fn api_method_upload_pxar() -> ApiAsyncMethod { ApiAsyncMethod::new( - upload_catar, - ObjectSchema::new("Upload .catar backup file.") + upload_pxar, + ObjectSchema::new("Upload .pxar backup file.") .required("store", StringSchema::new("Datastore name.")) .required("archive-name", StringSchema::new("Backup archive name.")) .required("backup-type", StringSchema::new("Backup type.") @@ -124,7 +124,7 @@ pub fn api_method_upload_catar() -> ApiAsyncMethod { ) } -fn download_catar( +fn download_pxar( _parts: Parts, _req_body: Body, param: Value, @@ -135,7 +135,7 @@ fn download_catar( let store = tools::required_string_param(¶m, "store")?; let mut archive_name = tools::required_string_param(¶m, "archive-name")?.to_owned(); - if !archive_name.ends_with(".catar") { + if !archive_name.ends_with(".pxar") { bail!("wrong archive extension"); } else { archive_name.push_str(".didx"); @@ -167,10 +167,10 @@ fn download_catar( Ok(Box::new(future::ok(response))) } -pub fn api_method_download_catar() -> ApiAsyncMethod { +pub fn api_method_download_pxar() -> ApiAsyncMethod { ApiAsyncMethod::new( - download_catar, - ObjectSchema::new("Download .catar backup file.") + download_pxar, + ObjectSchema::new("Download .pxar backup file.") .required("store", StringSchema::new("Datastore name.")) .required("archive-name", StringSchema::new("Backup archive name.")) .required("backup-type", StringSchema::new("Backup type.") diff --git a/src/api2/admin/datastore/upload.rs b/src/api2/admin/datastore/upload.rs index afe1c355..22b89d16 100644 --- a/src/api2/admin/datastore/upload.rs +++ b/src/api2/admin/datastore/upload.rs @@ -24,7 +24,7 @@ type Result = std::result::Result; pub fn api_method_upgrade_upload() -> ApiAsyncMethod { ApiAsyncMethod::new( upgrade_upload, - ObjectSchema::new("Download .catar backup file.") + ObjectSchema::new("Download .pxar backup file.") .required("store", StringSchema::new("Datastore name.")), ) } diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index 17791f77..195fd0bc 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -154,7 +154,7 @@ impl DynamicIndexReader { Ok(()) } - pub fn dump_catar(&self, mut writer: Box) -> Result<(), Error> { + pub fn dump_pxar(&self, mut writer: Box) -> Result<(), Error> { let mut buffer = Vec::with_capacity(1024*1024); diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 312a8612..5c9242eb 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -14,7 +14,7 @@ use proxmox_backup::client::*; use proxmox_backup::backup::*; //use proxmox_backup::backup::image_index::*; //use proxmox_backup::config::datastore; -//use proxmox_backup::catar::encoder::*; +//use proxmox_backup::pxar::encoder::*; //use proxmox_backup::backup::datastore::*; use serde_json::{json, Value}; @@ -26,7 +26,7 @@ use xdg::BaseDirectories; use lazy_static::lazy_static; lazy_static! { - static ref BACKUPSPEC_REGEX: Regex = Regex::new(r"^([a-zA-Z0-9_-]+\.(?:catar|raw)):(.+)$").unwrap(); + static ref BACKUPSPEC_REGEX: Regex = Regex::new(r"^([a-zA-Z0-9_-]+\.(?:pxar|raw)):(.+)$").unwrap(); } @@ -129,13 +129,13 @@ fn backup_directory>( let query = tools::json_object_to_query(param)?; - let path = format!("api2/json/admin/datastore/{}/catar?{}", repo.store(), query); + let path = format!("api2/json/admin/datastore/{}/pxar?{}", repo.store(), query); - let stream = CaTarBackupStream::open(dir_path.as_ref(), all_file_systems, verbose)?; + let stream = PxarBackupStream::open(dir_path.as_ref(), all_file_systems, verbose)?; let body = Body::wrap_stream(stream); - client.upload("application/x-proxmox-backup-catar", body, &path)?; + client.upload("application/x-proxmox-backup-pxar", body, &path)?; Ok(()) } @@ -183,6 +183,7 @@ fn strip_chunked_file_expenstions(list: Vec) -> Vec { result } +/* not used: fn list_backups( param: Value, _info: &ApiMethod, @@ -223,6 +224,7 @@ fn list_backups( //Ok(result) Ok(Value::Null) } + */ fn list_backup_groups( param: Value, @@ -474,8 +476,8 @@ fn complete_backup_source(arg: &str, param: &HashMap) -> Vec = arg.splitn(2, ':').collect(); if data.len() != 2 { - result.push(String::from("root.catar:/")); - result.push(String::from("etc.catar:/etc")); + result.push(String::from("root.pxar:/")); + result.push(String::from("etc.pxar:/etc")); return result; } @@ -544,13 +546,13 @@ fn restore( let target = tools::required_string_param(¶m, "target")?; - if archive_name.ends_with(".catar") { - let path = format!("api2/json/admin/datastore/{}/catar?{}", repo.store(), query); + if archive_name.ends_with(".pxar") { + let path = format!("api2/json/admin/datastore/{}/pxar?{}", repo.store(), query); println!("DOWNLOAD FILE {} to {}", path, target); let target = PathBuf::from(target); - let writer = CaTarBackupWriter::new(&target, true)?; + let writer = PxarBackupWriter::new(&target, true)?; client.download(&path, Box::new(writer))?; } else { bail!("unknown file extensions - unable to download '{}'", archive_name); diff --git a/src/bin/pxar.rs b/src/bin/pxar.rs index 75c8e038..05d01073 100644 --- a/src/bin/pxar.rs +++ b/src/bin/pxar.rs @@ -12,9 +12,9 @@ use serde_json::{Value}; use std::io::{Read, Write}; use std::path::PathBuf; -use proxmox_backup::catar::format_definition::*; -use proxmox_backup::catar::encoder::*; -use proxmox_backup::catar::decoder::*; +use proxmox_backup::pxar::format_definition::*; +use proxmox_backup::pxar::encoder::*; +use proxmox_backup::pxar::decoder::*; use proxmox_backup::tools::*; @@ -62,7 +62,7 @@ fn print_filenames( let mut reader = std::io::BufReader::new(file); - let mut decoder = CaTarDecoder::new(&mut reader)?; + let mut decoder = PxarDecoder::new(&mut reader)?; let root = decoder.root(); @@ -86,7 +86,7 @@ fn dump_archive( let archive = tools::required_string_param(¶m, "archive")?; let mut file = std::fs::File::open(archive)?; - println!("CATAR {}", archive); + println!("PXAR {}", archive); let mut buffer = [0u8; 16]; @@ -149,7 +149,7 @@ fn create_archive( let mut writer = std::io::BufWriter::with_capacity(1024*1024, file); - CaTarEncoder::encode(source, &mut dir, &mut writer, all_file_systems, verbose)?; + PxarEncoder::encode(source, &mut dir, &mut writer, all_file_systems, verbose)?; writer.flush()?; @@ -162,7 +162,7 @@ fn main() { .insert("create", CliCommand::new( ApiMethod::new( create_archive, - ObjectSchema::new("Create new catar archive.") + ObjectSchema::new("Create new .pxar archive.") .required("archive", StringSchema::new("Archive name")) .required("source", StringSchema::new("Source directory.")) .optional("verbose", BooleanSchema::new("Verbose output.").default(false)) diff --git a/src/client.rs b/src/client.rs index 6c36172f..3069f799 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,11 +6,11 @@ mod http_client; pub use http_client::*; -mod catar_backup_stream; -pub use catar_backup_stream::*; +mod pxar_backup_stream; +pub use pxar_backup_stream::*; -mod catar_decode_writer; -pub use catar_decode_writer::*; +mod pxar_decode_writer; +pub use pxar_decode_writer::*; mod backup_repo; pub use backup_repo::*; diff --git a/src/client/catar_backup_stream.rs b/src/client/pxar_backup_stream.rs similarity index 83% rename from src/client/catar_backup_stream.rs rename to src/client/pxar_backup_stream.rs index 66bbfa1e..48ca6e94 100644 --- a/src/client/catar_backup_stream.rs +++ b/src/client/pxar_backup_stream.rs @@ -11,22 +11,22 @@ use nix::fcntl::OFlag; use nix::sys::stat::Mode; use nix::dir::Dir; -use crate::catar::encoder::*; +use crate::pxar::encoder::*; -/// Stream implementation to encode and upload .catar archives. +/// Stream implementation to encode and upload .pxar archives. /// /// The hyper client needs an async Stream for file upload, so we -/// spawn an extra thread to encode the .catar data and pipe it to the +/// spawn an extra thread to encode the .pxar data and pipe it to the /// consumer. /// /// Note: The currect implementation is not fully ansync and can block. -pub struct CaTarBackupStream { +pub struct PxarBackupStream { pipe: Option, buffer: Vec, child: Option>, } -impl Drop for CaTarBackupStream { +impl Drop for PxarBackupStream { fn drop(&mut self) { drop(self.pipe.take()); @@ -34,7 +34,7 @@ impl Drop for CaTarBackupStream { } } -impl CaTarBackupStream { +impl PxarBackupStream { pub fn new(mut dir: Dir, path: PathBuf, all_file_systems: bool, verbose: bool) -> Result { let mut buffer = Vec::with_capacity(4096); @@ -44,8 +44,8 @@ impl CaTarBackupStream { let child = thread::spawn(move|| { let mut writer = unsafe { std::fs::File::from_raw_fd(tx) }; - if let Err(err) = CaTarEncoder::encode(path, &mut dir, &mut writer, all_file_systems, verbose) { - eprintln!("catar encode failed - {}", err); + if let Err(err) = PxarEncoder::encode(path, &mut dir, &mut writer, all_file_systems, verbose) { + eprintln!("pxar encode failed - {}", err); } }); @@ -63,7 +63,7 @@ impl CaTarBackupStream { } } -impl Stream for CaTarBackupStream { +impl Stream for PxarBackupStream { type Item = Vec; type Error = Error; diff --git a/src/client/catar_decode_writer.rs b/src/client/pxar_decode_writer.rs similarity index 75% rename from src/client/catar_decode_writer.rs rename to src/client/pxar_decode_writer.rs index 5da7cdc0..ec320bd3 100644 --- a/src/client/catar_decode_writer.rs +++ b/src/client/pxar_decode_writer.rs @@ -5,16 +5,16 @@ use std::os::unix::io::FromRawFd; use std::path::{Path, PathBuf}; use std::io::Write; -use crate::catar::decoder::*; +use crate::pxar::decoder::*; -/// Writer implementation to deccode a .catar archive (download). +/// Writer implementation to deccode a .pxar archive (download). -pub struct CaTarBackupWriter { +pub struct PxarBackupWriter { pipe: Option, child: Option>, } -impl Drop for CaTarBackupWriter { +impl Drop for PxarBackupWriter { fn drop(&mut self) { drop(self.pipe.take()); @@ -22,23 +22,23 @@ impl Drop for CaTarBackupWriter { } } -impl CaTarBackupWriter { +impl PxarBackupWriter { - pub fn new(base: &Path, verbose: bool) -> Result { + pub fn new(base: &Path, _verbose: bool) -> Result { let (rx, tx) = nix::unistd::pipe()?; let base = PathBuf::from(base); let child = thread::spawn(move|| { let mut reader = unsafe { std::fs::File::from_raw_fd(rx) }; - let mut decoder = CaTarDecoder::new(&mut reader); + let mut decoder = PxarDecoder::new(&mut reader); if let Err(err) = decoder.restore(&base, & |path| { println!("RESTORE: {:?}", path); Ok(()) }) { - eprintln!("catar decode failed - {}", err); + eprintln!("pxar decode failed - {}", err); } }); @@ -48,7 +48,7 @@ impl CaTarBackupWriter { } } -impl Write for CaTarBackupWriter { +impl Write for PxarBackupWriter { fn write(&mut self, buffer: &[u8]) -> Result { let pipe = match self.pipe { diff --git a/src/lib.rs b/src/lib.rs index 25060588..9921b4c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ pub mod server { } -pub mod catar; +pub mod pxar; pub mod section_config; diff --git a/src/catar.rs b/src/pxar.rs similarity index 85% rename from src/catar.rs rename to src/pxar.rs index a9688c63..91d79df6 100644 --- a/src/catar.rs +++ b/src/pxar.rs @@ -1,9 +1,10 @@ -//! *catar* Implementation +//! *pxar* Implementation //! -//! This is a implementation of the *catar* format used by the -//! [casync](https://github.com/systemd/casync) toolkit. It is a file -//! archive format defined by 'Lennart Poettering', specially defined -//! for efficent deduplication. +//! This code implements a slightly modified version of the *catar* +//! format used in the [casync](https://github.com/systemd/casync) +//! toolkit (we are not 100% binary compatible). It is a file archive +//! format defined by 'Lennart Poettering', specially defined for +//! efficent deduplication. //! Every archive contains items in the following order: //! * ENTRY -- containing general stat() data and related bits diff --git a/src/catar/binary_search_tree.rs b/src/pxar/binary_search_tree.rs similarity index 98% rename from src/catar/binary_search_tree.rs rename to src/pxar/binary_search_tree.rs index 2e021c68..717ada6e 100644 --- a/src/catar/binary_search_tree.rs +++ b/src/pxar/binary_search_tree.rs @@ -62,7 +62,7 @@ fn copy_binary_search_tree_inner( /// info. /// /// ``` -/// # use proxmox_backup::catar::binary_search_tree::copy_binary_search_tree; +/// # use proxmox_backup::pxar::binary_search_tree::copy_binary_search_tree; /// copy_binary_search_tree(5, |src, dest| { /// println!("Copy {} to {}", src, dest); /// }); diff --git a/src/catar/decoder.rs b/src/pxar/decoder.rs similarity index 98% rename from src/catar/decoder.rs rename to src/pxar/decoder.rs index d6be884b..bc105a36 100644 --- a/src/catar/decoder.rs +++ b/src/pxar/decoder.rs @@ -1,6 +1,6 @@ -//! *catar* format decoder. +//! *pxar* format decoder. //! -//! This module contain the code to decode *catar* archive files. +//! This module contain the code to decode *pxar* archive files. use failure::*; use endian_trait::Endian; @@ -22,14 +22,14 @@ use nix::errno::Errno; use nix::NixPath; // This one need Read, but works without Seek -pub struct CaTarDecoder<'a, R: Read> { +pub struct PxarDecoder<'a, R: Read> { reader: &'a mut R, skip_buffer: Vec, } const HEADER_SIZE: u64 = std::mem::size_of::() as u64; -impl <'a, R: Read> CaTarDecoder<'a, R> { +impl <'a, R: Read> PxarDecoder<'a, R> { pub fn new(reader: &'a mut R) -> Self { let mut skip_buffer = vec![0u8; 64*1024]; diff --git a/src/catar/encoder.rs b/src/pxar/encoder.rs similarity index 99% rename from src/catar/encoder.rs rename to src/pxar/encoder.rs index 5106764b..1a15df0f 100644 --- a/src/catar/encoder.rs +++ b/src/pxar/encoder.rs @@ -1,6 +1,6 @@ -//! *catar* format encoder. +//! *pxar* format encoder. //! -//! This module contain the code to generate *catar* archive files. +//! This module contain the code to generate *pxar* archive files. use failure::*; use endian_trait::Endian; @@ -27,7 +27,7 @@ use nix::sys::stat::FileStat; /// maximum memory usage. pub const MAX_DIRECTORY_ENTRIES: usize = 256*1024; -pub struct CaTarEncoder<'a, W: Write> { +pub struct PxarEncoder<'a, W: Write> { current_path: PathBuf, // used for error reporting writer: &'a mut W, writer_pos: usize, @@ -38,7 +38,7 @@ pub struct CaTarEncoder<'a, W: Write> { verbose: bool, } -impl <'a, W: Write> CaTarEncoder<'a, W> { +impl <'a, W: Write> PxarEncoder<'a, W> { pub fn encode( path: PathBuf, diff --git a/src/catar/format_definition.rs b/src/pxar/format_definition.rs similarity index 99% rename from src/catar/format_definition.rs rename to src/pxar/format_definition.rs index f9c82eeb..b03233e9 100644 --- a/src/catar/format_definition.rs +++ b/src/pxar/format_definition.rs @@ -1,4 +1,4 @@ -//! *catar* binary format definition +//! *pxar* binary format definition //! //! Please note the all values are stored in little endian ordering. //! diff --git a/src/catar/inspector.rs b/src/pxar/inspector.rs similarity index 99% rename from src/catar/inspector.rs rename to src/pxar/inspector.rs index 88835402..5964d18f 100644 --- a/src/catar/inspector.rs +++ b/src/pxar/inspector.rs @@ -1,6 +1,6 @@ -//! *catar* format decoder. +//! *pxar* format decoder. //! -//! This module contain the code to decode *catar* archive files. +//! This module contain the code to decode *pxar* archive files. use failure::*; use endian_trait::Endian; @@ -30,7 +30,7 @@ pub struct CaDirectoryEntry { } // This one needs Read+Seek (we may want one without Seek?) -pub struct CaTarDecoder<'a, R: Read + Seek> { +pub struct PxarDecoder<'a, R: Read + Seek> { reader: &'a mut R, root_start: u64, root_end: u64, @@ -38,7 +38,7 @@ pub struct CaTarDecoder<'a, R: Read + Seek> { const HEADER_SIZE: u64 = std::mem::size_of::() as u64; -impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { +impl <'a, R: Read + Seek> PxarDecoder<'a, R> { pub fn new(reader: &'a mut R) -> Result {