all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/3] debug: move outfile_or_stdout to module for reuse
Date: Mon, 23 May 2022 16:11:34 +0200	[thread overview]
Message-ID: <20220523141135.921321-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20220523141135.921321-1-f.gruenbichler@proxmox.com>

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 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<P: AsRef<Path>>(
-    path: Option<P>,
-) -> std::io::Result<Box<dyn Write + Send + Sync + Unpin + RefUnwindSafe + UnwindSafe>> {
-    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<P: AsRef<Path>>(
+    path: Option<P>,
+) -> std::io::Result<Box<dyn Write + Send + Sync + Unpin + RefUnwindSafe + UnwindSafe>> {
+    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





  reply	other threads:[~2022-05-23 14:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 14:11 [pbs-devel] [PATCH proxmox-backup 1/3] debug: recover: allow ignoring missing/corrupt chunks Fabian Grünbichler
2022-05-23 14:11 ` Fabian Grünbichler [this message]
2022-05-23 14:11 ` [pbs-devel] [PATCH proxmox-backup 3/3] debug: recover: allow overriding output-path Fabian Grünbichler
2022-05-24  9:16 ` [pbs-devel] [PATCH proxmox-backup 1/3] debug: recover: allow ignoring missing/corrupt chunks Hannes Laimer
2022-05-24  9:47 ` [pbs-devel] applied-series: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220523141135.921321-2-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal