From 00c88a42a2eb67a87a2ed00862b0762476527eb5 Mon Sep 17 00:00:00 2001 From: Gabriel Goller Date: Tue, 18 Jun 2024 16:22:03 +0200 Subject: [PATCH] pxar: use anyhow::Error in PxarBackupStream 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 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pbs-client/src/pxar_backup_stream.rs b/pbs-client/src/pxar_backup_stream.rs index cdbcdfec..4370da6c 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::{mpsc, 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; @@ -29,7 +29,7 @@ pub struct PxarBackupStream { rx: Option, Error>>>, pub suggested_boundaries: Option>, handle: Option, - error: Arc>>, + error: Arc>>, } impl Drop for PxarBackupStream { @@ -98,7 +98,7 @@ impl PxarBackupStream { .await { let mut error = error2.lock().unwrap(); - *error = Some(err.to_string()); + *error = Some(err); } }; @@ -142,18 +142,18 @@ 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 let Some(err) = error.take() { + 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 let Some(err) = error.take() { + return Poll::Ready(Some(Err(err))); } Poll::Ready(None) // channel closed, no error } -- 2.39.5