diff --git a/swap/src/monero/wallet_rpc.rs b/swap/src/monero/wallet_rpc.rs index 2cfe1324..1501aa10 100644 --- a/swap/src/monero/wallet_rpc.rs +++ b/swap/src/monero/wallet_rpc.rs @@ -1,5 +1,5 @@ use ::monero::Network; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use async_compression::tokio::bufread::BzDecoder; use big_bytes::BigByte; use futures::{StreamExt, TryStreamExt}; @@ -31,6 +31,10 @@ compile_error!("unsupported operating system"); const PACKED_FILE: &str = "monero-wallet-rpc"; +#[derive(Debug, Clone, Copy, thiserror::Error)] +#[error("monero wallet rpc executable not found in downloaded archive")] +pub struct ExecutableNotFoundInArchive; + pub struct WalletRpcProcess { _child: Child, port: u16, @@ -109,17 +113,22 @@ impl WalletRpc { let mut ar = Archive::new(file); let mut entries = ar.entries()?; - while let Some(file) = entries.next().await { - let mut f = file?; - if f.path()? - .to_str() - .context("Could not find convert path to str in tar ball")? - .contains(PACKED_FILE) - { - f.unpack(monero_wallet_rpc.exec_path()).await?; + loop { + match entries.next().await { + Some(file) => { + let mut f = file?; + if f.path()? + .to_str() + .context("Could not find convert path to str in tar ball")? + .contains(PACKED_FILE) + { + f.unpack(monero_wallet_rpc.exec_path()).await?; + break; + } + } + None => bail!(ExecutableNotFoundInArchive), } } - remove_file(monero_wallet_rpc.tar_path()).await?; }