From e5f9b7f79e922eafdc08a35b764eca257bf3cc4d Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 31 Aug 2021 14:45:48 +0200 Subject: [PATCH] split out proxmox-backup-debug binary and introduce pbs_tools::cli module Signed-off-by: Wolfgang Bumiller --- Cargo.toml | 1 + Makefile | 3 +++ pbs-tools/src/cli.rs | 13 +++++++++++++ pbs-tools/src/lib.rs | 1 + proxmox-backup-debug/Cargo.toml | 17 +++++++++++++++++ .../src}/inspect.rs | 2 +- proxmox-backup-debug/src/main.rs | 13 +++++++++++++ .../src}/recover.rs | 0 src/bin/proxmox-backup-debug.rs | 15 --------------- src/bin/proxmox_backup_debug/mod.rs | 4 ---- src/tools/mod.rs | 13 ------------- 11 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 pbs-tools/src/cli.rs create mode 100644 proxmox-backup-debug/Cargo.toml rename {src/bin/proxmox_backup_debug => proxmox-backup-debug/src}/inspect.rs (99%) create mode 100644 proxmox-backup-debug/src/main.rs rename {src/bin/proxmox_backup_debug => proxmox-backup-debug/src}/recover.rs (100%) delete mode 100644 src/bin/proxmox-backup-debug.rs delete mode 100644 src/bin/proxmox_backup_debug/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 40b75124..0568bbce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ members = [ "proxmox-backup-banner", "proxmox-backup-client", + "proxmox-backup-debug", "pxar-bin", ] diff --git a/Makefile b/Makefile index dbbe5492..20a92b2e 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ SUBCRATES := \ pbs-tools \ proxmox-backup-banner \ proxmox-backup-client \ + proxmox-backup-debug \ pxar-bin ifeq ($(BUILD_MODE), release) @@ -171,6 +172,8 @@ $(COMPILED_BINS) $(COMPILEDIR)/dump-catalog-shell-cli $(COMPILEDIR)/docgen: .do- --bin proxmox-backup-banner \ --package proxmox-backup-client \ --bin proxmox-backup-client \ + --package proxmox-backup-debug \ + --bin proxmox-backup-debug \ --package pxar-bin \ --bin pxar \ --package proxmox-backup \ diff --git a/pbs-tools/src/cli.rs b/pbs-tools/src/cli.rs new file mode 100644 index 00000000..069b23e2 --- /dev/null +++ b/pbs-tools/src/cli.rs @@ -0,0 +1,13 @@ +use std::fs::File; +use std::io::{self, stdout, Write}; +use std::path::Path; + +/// Returns either a new file, if a path is given, or stdout, if no path is given. +pub fn outfile_or_stdout>(path: Option

) -> io::Result> { + if let Some(path) = path { + let f = File::create(path)?; + Ok(Box::new(f) as Box) + } else { + Ok(Box::new(stdout()) as Box) + } +} diff --git a/pbs-tools/src/lib.rs b/pbs-tools/src/lib.rs index 683afbba..1a8dc114 100644 --- a/pbs-tools/src/lib.rs +++ b/pbs-tools/src/lib.rs @@ -4,6 +4,7 @@ pub mod blocking; pub mod borrow; pub mod broadcast_future; pub mod cert; +pub mod cli; pub mod compression; pub mod format; pub mod fs; diff --git a/proxmox-backup-debug/Cargo.toml b/proxmox-backup-debug/Cargo.toml new file mode 100644 index 00000000..3fea04b0 --- /dev/null +++ b/proxmox-backup-debug/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "proxmox-backup-debug" +version = "0.1.0" +authors = ["Proxmox Support Team "] +edition = "2018" + +[dependencies] +anyhow = "1.0" +walkdir = "2" +serde_json = "1.0" + +proxmox = { version = "0.13.0", features = [ "api-macro", "cli", "router" ] } + +pbs-client = { path = "../pbs-client" } +pbs-datastore = { path = "../pbs-datastore" } +pbs-runtime = { path = "../pbs-runtime" } +pbs-tools = { path = "../pbs-tools" } diff --git a/src/bin/proxmox_backup_debug/inspect.rs b/proxmox-backup-debug/src/inspect.rs similarity index 99% rename from src/bin/proxmox_backup_debug/inspect.rs rename to proxmox-backup-debug/src/inspect.rs index c978514d..ee05e8b5 100644 --- a/src/bin/proxmox_backup_debug/inspect.rs +++ b/proxmox-backup-debug/src/inspect.rs @@ -23,7 +23,7 @@ use pbs_datastore::{load_and_decrypt_key, CryptConfig, DataBlob}; use pbs_client::tools::key_source::get_encryption_key_password; -use proxmox_backup::tools::outfile_or_stdout; +use pbs_tools::cli::outfile_or_stdout; /// Decodes a blob and writes its content either to stdout or into a file fn decode_blob( diff --git a/proxmox-backup-debug/src/main.rs b/proxmox-backup-debug/src/main.rs new file mode 100644 index 00000000..b768f57a --- /dev/null +++ b/proxmox-backup-debug/src/main.rs @@ -0,0 +1,13 @@ +use proxmox::api::cli::{run_cli_command, CliCommandMap, CliEnvironment}; + +mod inspect; +mod recover; + +fn main() { + let cmd_def = CliCommandMap::new() + .insert("inspect", inspect::inspect_commands()) + .insert("recover", recover::recover_commands()); + + let rpcenv = CliEnvironment::new(); + run_cli_command(cmd_def, rpcenv, Some(|future| pbs_runtime::main(future))); +} diff --git a/src/bin/proxmox_backup_debug/recover.rs b/proxmox-backup-debug/src/recover.rs similarity index 100% rename from src/bin/proxmox_backup_debug/recover.rs rename to proxmox-backup-debug/src/recover.rs diff --git a/src/bin/proxmox-backup-debug.rs b/src/bin/proxmox-backup-debug.rs deleted file mode 100644 index b3360c93..00000000 --- a/src/bin/proxmox-backup-debug.rs +++ /dev/null @@ -1,15 +0,0 @@ -use proxmox::api::cli::*; - -mod proxmox_backup_debug; -use proxmox_backup_debug::{inspect_commands, recover_commands}; - -fn main() { - proxmox_backup::tools::setup_safe_path_env(); - - let cmd_def = CliCommandMap::new() - .insert("inspect", inspect_commands()) - .insert("recover", recover_commands()); - - let rpcenv = CliEnvironment::new(); - run_cli_command(cmd_def, rpcenv, Some(|future| pbs_runtime::main(future))); -} diff --git a/src/bin/proxmox_backup_debug/mod.rs b/src/bin/proxmox_backup_debug/mod.rs deleted file mode 100644 index 62df7754..00000000 --- a/src/bin/proxmox_backup_debug/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inspect; -pub use inspect::*; -mod recover; -pub use recover::*; diff --git a/src/tools/mod.rs b/src/tools/mod.rs index dfff8c10..b6c55ac2 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -2,10 +2,7 @@ //! //! This is a collection of small and useful tools. use std::any::Any; -use std::fs::File; -use std::io::{stdout, Write}; use std::os::unix::io::RawFd; -use std::path::Path; use anyhow::{bail, format_err, Error}; use openssl::hash::{hash, DigestBytes, MessageDigest}; @@ -227,13 +224,3 @@ pub fn create_run_dir() -> Result<(), Error> { let _: bool = create_path(pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR_M!(), None, Some(opts))?; Ok(()) } - -/// Returns either a new file, if a path is given, or stdout, if no path is given. -pub fn outfile_or_stdout>(path: Option

) -> Result, Error> { - if let Some(path) = path { - let f = File::create(path)?; - Ok(Box::new(f) as Box) - } else { - Ok(Box::new(stdout()) as Box) - } -}