From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id EE5E5723A5 for ; Mon, 23 May 2022 16:12:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E4F57C588 for ; Mon, 23 May 2022 16:11:46 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 6F246C57F for ; Mon, 23 May 2022 16:11:45 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 696CA43801 for ; Mon, 23 May 2022 16:11:44 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Mon, 23 May 2022 16:11:34 +0200 Message-Id: <20220523141135.921321-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220523141135.921321-1-f.gruenbichler@proxmox.com> References: <20220523141135.921321-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.171 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup 2/3] debug: move outfile_or_stdout to module for reuse X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2022 14:12:17 -0000 Signed-off-by: Fabian Grünbichler --- src/bin/proxmox_backup_debug/inspect.rs | 18 +++--------------- src/bin/proxmox_backup_debug/mod.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/bin/proxmox_backup_debug/inspect.rs b/src/bin/proxmox_backup_debug/inspect.rs index 37bc6e05..e50c50cc 100644 --- a/src/bin/proxmox_backup_debug/inspect.rs +++ b/src/bin/proxmox_backup_debug/inspect.rs @@ -1,7 +1,6 @@ use std::collections::HashSet; use std::fs::File; -use std::io::{stdout, Read, Seek, SeekFrom, Write}; -use std::panic::{RefUnwindSafe, UnwindSafe}; +use std::io::{Read, Seek, SeekFrom, Write}; use std::path::Path; use anyhow::{bail, format_err, Error}; @@ -27,18 +26,6 @@ use pbs_datastore::index::IndexFile; use pbs_datastore::DataBlob; use pbs_tools::crypt_config::CryptConfig; -// Returns either a new file, if a path is given, or stdout, if no path is given. -fn outfile_or_stdout>( - path: Option

, -) -> std::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<_>) - } -} - /// Decodes a blob and writes its content either to stdout or into a file fn decode_blob( mut output_path: Option<&Path>, @@ -61,7 +48,8 @@ fn decode_blob( _ => output_path, }; - outfile_or_stdout(output_path)?.write_all(blob.decode(crypt_conf_opt, digest)?.as_slice())?; + crate::outfile_or_stdout(output_path)? + .write_all(blob.decode(crypt_conf_opt, digest)?.as_slice())?; Ok(()) } diff --git a/src/bin/proxmox_backup_debug/mod.rs b/src/bin/proxmox_backup_debug/mod.rs index f092c585..31bc68c3 100644 --- a/src/bin/proxmox_backup_debug/mod.rs +++ b/src/bin/proxmox_backup_debug/mod.rs @@ -1,3 +1,22 @@ +use std::{ + fs::File, + io::{stdout, Write}, + panic::{RefUnwindSafe, UnwindSafe}, + path::Path, +}; + pub mod api; pub mod inspect; pub mod recover; + +// Returns either a new file, if a path is given, or stdout, if no path is given. +pub(crate) fn outfile_or_stdout>( + path: Option

, +) -> std::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<_>) + } +} -- 2.30.2