From d0c079d70c180f7eb1a4d67342430ff2ecdcc29c 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 | 4 ++-- src/lib.rs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index db9ee86..f6d750c 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,9 @@ use bitcoin_hashes::{sha256, Hash}; use std::fs; use std::io::Read; +use std::os::unix::fs::PermissionsExt; use std::path::Path; use std::str::FromStr; -use std::os::unix::fs::PermissionsExt; include!("src/versions.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 8f1427f..0dd21eb 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!(), } }