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 151B692263 for ; Fri, 16 Feb 2024 16:33:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EC2835579 for ; Fri, 16 Feb 2024 16:33:21 +0100 (CET) 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 for ; Fri, 16 Feb 2024 16:33:21 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D7C9948580 for ; Fri, 16 Feb 2024 16:33:20 +0100 (CET) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Fri, 16 Feb 2024 16:33:11 +0100 Message-ID: <20240216153317.323260-5-g.goller@proxmox.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216153317.323260-1-g.goller@proxmox.com> References: <20240216153317.323260-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.101 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 4/4] pxar: use anyhow::Error in PxarBackupStream 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: Fri, 16 Feb 2024 15:33:52 -0000 Instead of storing the error as a string in the PxarBackupStream, we store it as an anyhow::Error. As we can't clone an anyhow::Error, we take it out from the mutex and return it. This won't change anything as the consumation of the stream will stop if it gets a Some(Err(..)). Signed-off-by: Gabriel Goller --- pbs-client/src/pxar_backup_stream.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pbs-client/src/pxar_backup_stream.rs b/pbs-client/src/pxar_backup_stream.rs index 22a6ffdc..4dbfd472 100644 --- a/pbs-client/src/pxar_backup_stream.rs +++ b/pbs-client/src/pxar_backup_stream.rs @@ -5,7 +5,7 @@ use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; -use anyhow::{format_err, Error}; +use anyhow::Error; use futures::future::{AbortHandle, Abortable}; use futures::stream::Stream; use nix::dir::Dir; @@ -25,7 +25,7 @@ use pbs_datastore::catalog::CatalogWriter; pub struct PxarBackupStream { rx: Option, Error>>>, handle: Option, - error: Arc>>, + error: Arc>>, } impl Drop for PxarBackupStream { @@ -68,7 +68,7 @@ impl PxarBackupStream { .await { let mut error = error2.lock().unwrap(); - *error = Some(err.to_string()); + *error = Some(err); } }; @@ -100,18 +100,20 @@ impl Stream for PxarBackupStream { fn poll_next(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { { // limit lock scope - let error = self.error.lock().unwrap(); - if let Some(ref msg) = *error { - return Poll::Ready(Some(Err(format_err!("{}", msg)))); + let mut error = self.error.lock().unwrap(); + if error.is_some() { + let err = error.take().unwrap(); + return Poll::Ready(Some(Err(err))); } } match proxmox_async::runtime::block_in_place(|| self.rx.as_ref().unwrap().recv()) { Ok(data) => Poll::Ready(Some(data)), Err(_) => { - let error = self.error.lock().unwrap(); - if let Some(ref msg) = *error { - return Poll::Ready(Some(Err(format_err!("{}", msg)))); + let mut error = self.error.lock().unwrap(); + if error.is_some() { + let err = error.take().unwrap(); + return Poll::Ready(Some(Err(err))); } Poll::Ready(None) // channel closed, no error } -- 2.43.0