pxar bin: rust fmt

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-04-06 16:58:04 +02:00
parent c650378a39
commit 48fcee6a50
2 changed files with 27 additions and 44 deletions

View File

@ -3,8 +3,8 @@ use std::ffi::OsStr;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::OpenOptionsExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use futures::future::FutureExt; use futures::future::FutureExt;
@ -12,10 +12,12 @@ use futures::select;
use tokio::signal::unix::{signal, SignalKind}; use tokio::signal::unix::{signal, SignalKind};
use pathpatterns::{MatchEntry, MatchType, PatternFlag}; use pathpatterns::{MatchEntry, MatchType, PatternFlag};
use pbs_client::pxar::{fuse, format_single_line_entry, ENCODER_MAX_ENTRIES, Flags, PxarExtractOptions}; use pbs_client::pxar::{
format_single_line_entry, fuse, Flags, PxarExtractOptions, ENCODER_MAX_ENTRIES,
};
use proxmox_schema::api;
use proxmox_router::cli::*; use proxmox_router::cli::*;
use proxmox_schema::api;
fn extract_archive_from_reader<R: std::io::Read>( fn extract_archive_from_reader<R: std::io::Read>(
reader: &mut R, reader: &mut R,
@ -151,8 +153,7 @@ fn extract_archive(
let mut match_list = Vec::new(); let mut match_list = Vec::new();
if let Some(filename) = &files_from { if let Some(filename) = &files_from {
for line in proxmox_sys::fs::file_get_non_comment_lines(filename)? { for line in proxmox_sys::fs::file_get_non_comment_lines(filename)? {
let line = line let line = line.map_err(|err| format_err!("error reading {}: {}", filename, err))?;
.map_err(|err| format_err!("error reading {}: {}", filename, err))?;
match_list.push( match_list.push(
MatchEntry::parse_pattern(line, PatternFlag::PATH_NAME, MatchType::Include) MatchEntry::parse_pattern(line, PatternFlag::PATH_NAME, MatchType::Include)
.map_err(|err| format_err!("bad pattern in file '{}': {}", filename, err))?, .map_err(|err| format_err!("bad pattern in file '{}': {}", filename, err))?,
@ -180,7 +181,8 @@ fn extract_archive(
was_ok.store(false, Ordering::Release); was_ok.store(false, Ordering::Release);
eprintln!("error: {}", err); eprintln!("error: {}", err);
Ok(()) Ok(())
}) as Box<dyn FnMut(Error) -> Result<(), Error> + Send>) })
as Box<dyn FnMut(Error) -> Result<(), Error> + Send>)
}; };
let options = PxarExtractOptions { let options = PxarExtractOptions {
@ -193,26 +195,14 @@ fn extract_archive(
if archive == "-" { if archive == "-" {
let stdin = std::io::stdin(); let stdin = std::io::stdin();
let mut reader = stdin.lock(); let mut reader = stdin.lock();
extract_archive_from_reader( extract_archive_from_reader(&mut reader, target, feature_flags, verbose, options)?;
&mut reader,
target,
feature_flags,
verbose,
options,
)?;
} else { } else {
if verbose { if verbose {
println!("PXAR extract: {}", archive); println!("PXAR extract: {}", archive);
} }
let file = std::fs::File::open(archive)?; let file = std::fs::File::open(archive)?;
let mut reader = std::io::BufReader::new(file); let mut reader = std::io::BufReader::new(file);
extract_archive_from_reader( extract_archive_from_reader(&mut reader, target, feature_flags, verbose, options)?;
&mut reader,
target,
feature_flags,
verbose,
options,
)?;
} }
if !was_ok.load(Ordering::Acquire) { if !was_ok.load(Ordering::Acquire) {
@ -332,7 +322,6 @@ async fn create_archive(
skip_lost_and_found: false, skip_lost_and_found: false,
}; };
let source = PathBuf::from(source); let source = PathBuf::from(source);
let dir = nix::dir::Dir::open( let dir = nix::dir::Dir::open(
@ -381,7 +370,8 @@ async fn create_archive(
}, },
None, None,
options, options,
).await?; )
.await?;
Ok(()) Ok(())
} }
@ -400,11 +390,7 @@ async fn create_archive(
}, },
)] )]
/// Mount the archive to the provided mountpoint via FUSE. /// Mount the archive to the provided mountpoint via FUSE.
async fn mount_archive( async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Result<(), Error> {
archive: String,
mountpoint: String,
verbose: bool,
) -> Result<(), Error> {
let archive = Path::new(&archive); let archive = Path::new(&archive);
let mountpoint = Path::new(&mountpoint); let mountpoint = Path::new(&mountpoint);
let options = OsStr::new("ro,default_permissions"); let options = OsStr::new("ro,default_permissions");
@ -487,7 +473,9 @@ fn main() {
); );
let rpcenv = CliEnvironment::new(); let rpcenv = CliEnvironment::new();
run_cli_command(cmd_def, rpcenv, Some(|future| { run_cli_command(
proxmox_async::runtime::main(future) cmd_def,
})); rpcenv,
Some(|future| proxmox_async::runtime::main(future)),
);
} }

View File

@ -20,9 +20,7 @@ fn pxar_create_and_extract() {
.arg("./tests/archive.pxar") .arg("./tests/archive.pxar")
.arg(src_dir) .arg(src_dir)
.status() .status()
.unwrap_or_else(|err| { .unwrap_or_else(|err| panic!("Failed to invoke '{}': {}", exec_path, err));
panic!("Failed to invoke '{}': {}", exec_path, err)
});
println!("run '{} extract archive.pxar {}'", exec_path, dest_dir); println!("run '{} extract archive.pxar {}'", exec_path, dest_dir);
@ -32,13 +30,14 @@ fn pxar_create_and_extract() {
.arg("--target") .arg("--target")
.arg(dest_dir) .arg(dest_dir)
.status() .status()
.unwrap_or_else(|err| { .unwrap_or_else(|err| panic!("Failed to invoke '{}': {}", exec_path, err));
panic!("Failed to invoke '{}': {}", exec_path, err)
});
println!("run 'rsync --dry-run --itemize-changes --archive {} {}' to verify'", src_dir, dest_dir); println!(
"run 'rsync --dry-run --itemize-changes --archive {} {}' to verify'",
src_dir, dest_dir
);
/* Use rsync with --dry-run and --itemize-changes to compare /* Use rsync with --dry-run and --itemize-changes to compare
src_dir and dest_dir */ src_dir and dest_dir */
let stdout = Command::new("rsync") let stdout = Command::new("rsync")
.arg("--dry-run") .arg("--dry-run")
.arg("--itemize-changes") .arg("--itemize-changes")
@ -64,18 +63,14 @@ fn pxar_create_and_extract() {
Command::new("rm") Command::new("rm")
.arg("./tests/archive.pxar") .arg("./tests/archive.pxar")
.status() .status()
.unwrap_or_else(|err| { .unwrap_or_else(|err| panic!("Failed to invoke 'rm': {}", err));
panic!("Failed to invoke 'rm': {}", err)
});
// Cleanup destination dir // Cleanup destination dir
Command::new("rm") Command::new("rm")
.arg("-r") .arg("-r")
.arg(dest_dir) .arg(dest_dir)
.status() .status()
.unwrap_or_else(|err| { .unwrap_or_else(|err| panic!("Failed to invoke 'rm': {}", err));
panic!("Failed to invoke 'rm': {}", err)
});
// If source and destination folder contain the same content, // If source and destination folder contain the same content,
// the output of the rsync invokation should yield no lines. // the output of the rsync invokation should yield no lines.