diff --git a/Cargo.toml b/Cargo.toml index 1ebda322..e692e6af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ members = [ "pbs-tools", "proxmox-backup-banner", + "pxar-bin", ] [lib] diff --git a/Makefile b/Makefile index e0fcaf62..bf4076f5 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,8 @@ SUBCRATES := \ pbs-runtime \ pbs-systemd \ pbs-tools \ - proxmox-backup-banner + proxmox-backup-banner \ + pxar-bin ifeq ($(BUILD_MODE), release) CARGO_BUILD_ARGS += --release @@ -163,6 +164,8 @@ $(COMPILED_BINS) $(COMPILEDIR)/dump-catalog-shell-cli $(COMPILEDIR)/docgen: .do- $(CARGO) build $(CARGO_BUILD_ARGS) \ --package proxmox-backup-banner \ --bin proxmox-backup-banner \ + --package pxar-bin \ + --bin pxar \ --package proxmox-backup \ --bin dump-catalog-shell-cli \ --bin pmt --bin pmtx \ diff --git a/pbs-tools/src/fs.rs b/pbs-tools/src/fs.rs index 1d2699ca..4af75e1d 100644 --- a/pbs-tools/src/fs.rs +++ b/pbs-tools/src/fs.rs @@ -2,9 +2,12 @@ use std::borrow::{Borrow, BorrowMut}; use std::collections::HashMap; +use std::fs::File; use std::hash::BuildHasher; +use std::io::{self, BufRead}; use std::ops::{Deref, DerefMut}; use std::os::unix::io::{AsRawFd, RawFd}; +use std::path::Path; use anyhow::{bail, format_err, Error}; use nix::dir; @@ -401,3 +404,27 @@ where result } + +/// Get an iterator over lines of a file, skipping empty lines and comments (lines starting with a +/// `#`). +pub fn file_get_non_comment_lines>( + path: P, +) -> Result>, Error> { + let path = path.as_ref(); + + Ok(io::BufReader::new( + File::open(path).map_err(|err| format_err!("error opening {:?}: {}", path, err))?, + ) + .lines() + .filter_map(|line| match line { + Ok(line) => { + let line = line.trim(); + if line.is_empty() || line.starts_with('#') { + None + } else { + Some(Ok(line.to_string())) + } + } + Err(err) => Some(Err(err)), + })) +} diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml new file mode 100644 index 00000000..0d1c7d91 --- /dev/null +++ b/pxar-bin/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "pxar-bin" +version = "0.1.0" +authors = ["Proxmox Support Team "] +edition = "2018" + +[[bin]] +name = "pxar" +path = "src/main.rs" + +[dependencies] +anyhow = "1.0" +futures = "0.3" +nix = "0.19.1" +serde_json = "1.0" +tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] } + +pathpatterns = "0.1.2" +proxmox = { version = "0.11.5", default-features = false, features = [] } +pxar = { version = "0.10.1", features = [ "tokio-io" ] } + +pbs-client = { path = "../pbs-client" } +pbs-runtime = { path = "../pbs-runtime" } +pbs-tools = { path = "../pbs-tools" } diff --git a/src/bin/pxar.rs b/pxar-bin/src/main.rs similarity index 99% rename from src/bin/pxar.rs rename to pxar-bin/src/main.rs index e4eac0d7..ede97d8f 100644 --- a/src/bin/pxar.rs +++ b/pxar-bin/src/main.rs @@ -150,7 +150,7 @@ fn extract_archive( let mut match_list = Vec::new(); if let Some(filename) = &files_from { - for line in proxmox_backup::tools::file_get_non_comment_lines(filename)? { + for line in pbs_tools::fs::file_get_non_comment_lines(filename)? { let line = line .map_err(|err| format_err!("error reading {}: {}", filename, err))?; match_list.push( diff --git a/src/tools/mod.rs b/src/tools/mod.rs index d13c4d45..a6379a96 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -278,30 +278,6 @@ pub fn pbs_simple_http(proxy_config: Option) -> SimpleHttp { SimpleHttp::with_options(options) } -/// Get an iterator over lines of a file, skipping empty lines and comments (lines starting with a -/// `#`). -pub fn file_get_non_comment_lines>( - path: P, -) -> Result>, Error> { - let path = path.as_ref(); - - Ok(io::BufReader::new( - File::open(path).map_err(|err| format_err!("error opening {:?}: {}", path, err))?, - ) - .lines() - .filter_map(|line| match line { - Ok(line) => { - let line = line.trim(); - if line.is_empty() || line.starts_with('#') { - None - } else { - Some(Ok(line.to_string())) - } - } - Err(err) => Some(Err(err)), - })) -} - pub fn setup_safe_path_env() { std::env::set_var("PATH", "/sbin:/bin:/usr/sbin:/usr/bin"); // Make %ENV safer - as suggested by https://perldoc.perl.org/perlsec.html