Bail if monero wallet rpc is not found in downloaded archive

Previously we were ignoring if the monero wallet rpc was not found and
unpacked from archive leading to a failure down the line when trying to
run a non-existent executable. Bail when the executable is no found in
the archive.
pull/253/head
rishflab 3 years ago
parent 17278d1278
commit 27df9128be

@ -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?;
}

Loading…
Cancel
Save