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 0ACA992391 for ; Fri, 16 Feb 2024 18:47:24 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E15556A4A for ; Fri, 16 Feb 2024 18:47:23 +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 18:47:22 +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 A0E4445C12 for ; Fri, 16 Feb 2024 18:47:22 +0100 (CET) Message-ID: Date: Fri, 16 Feb 2024 18:47:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pbs-devel@lists.proxmox.com References: <20240216153317.323260-1-g.goller@proxmox.com> <20240216153317.323260-5-g.goller@proxmox.com> From: Max Carrara In-Reply-To: <20240216153317.323260-5-g.goller@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.006 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: Re: [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 17:47:24 -0000 On 2/16/24 16:33, Gabriel Goller wrote: > 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)))); This here: > + let mut error = self.error.lock().unwrap(); > + if error.is_some() { > + let err = error.take().unwrap(); > + return Poll::Ready(Some(Err(err))); > } ... could be replaced with the following: let mut error = self.error.lock().unwrap(); if let Some(err) = error.take() { return Poll::Ready(Some(Err(err))); } `Option::take()` also returns an `Option`, allowing you to omit the `unwrap()`. > } > > 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))); > } Same as above here. > Poll::Ready(None) // channel closed, no error > }