From 996fe2a8e563bc1bde6bbc2e0c2a2f4421abcdbc Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Fri, 5 Apr 2024 18:53:13 +0300 Subject: [PATCH] Add ELECTRUMD_SKIP_DOWNLOAD option Context: https://github.com/Blockstream/electrs/pull/73 --- build.rs | 2 +- src/lib.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index 8d72817..6474163 100644 --- a/build.rs +++ b/build.rs @@ -21,7 +21,7 @@ fn get_expected_sha256() -> Result { } fn main() { - if !HAS_FEATURE { + if !HAS_FEATURE || std::env::var_os("ELECTRUMD_SKIP_DOWNLOAD").is_some() { return; } let download_filename = download_filename(); diff --git a/src/lib.rs b/src/lib.rs index 1a1773a..6082809 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,8 @@ pub enum Error { NeitherFeatureNorEnvVar, /// Returned when calling methods requiring either a feature or anv var, but both are present BothFeatureAndEnvVar, + /// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set + SkipDownload, } impl fmt::Debug for Error { @@ -81,6 +83,7 @@ impl fmt::Debug for Error { Error::NoEnvVar => write!(f, "Called a method requiring env var `ELECTRUMD_EXE` to be set, but it's not"), Error::NeitherFeatureNorEnvVar => write!(f, "Called a method requiring env var `ELECTRUMD_EXE` or a feature to be set, but neither are set"), Error::BothFeatureAndEnvVar => write!(f, "Called a method requiring env var `ELECTRUMD_EXE` or a feature to be set, but both are set"), + Error::SkipDownload => write!(f, "expecting an auto-downloaded executable but `ELECTRUMD_SKIP_DOWNLOAD` env var is set"), } } } @@ -300,14 +303,16 @@ fn rand_string() -> String { /// Provide the electrum executable path if a version feature has been specified pub fn downloaded_exe_path() -> Result { - if versions::HAS_FEATURE { + if std::env::var_os("ELECTRUMD_SKIP_DOWNLOAD").is_some() { + Err(Error::SkipDownload) + } else if !versions::HAS_FEATURE { + Err(Error::NoFeature) + } else { Ok(format!( "{}/electrum/electrum-{}/electrum.AppImage", env!("OUT_DIR"), versions::VERSION )) - } else { - Err(Error::NoFeature) } } @@ -318,7 +323,9 @@ pub fn exe_path() -> Result { (Ok(_), Ok(_)) => Err(Error::BothFeatureAndEnvVar), (Ok(path), Err(_)) => Ok(path), (Err(_), Ok(path)) => Ok(path), - (Err(_), Err(_)) => Err(Error::NeitherFeatureNorEnvVar), + (Err(Error::NoFeature), Err(_)) => Err(Error::NeitherFeatureNorEnvVar), + (Err(Error::SkipDownload), Err(_)) => Err(Error::SkipDownload), + (Err(_), Err(_)) => unreachable!(), } }