Skip to content

Commit

Permalink
Add ELECTRUMD_SKIP_DOWNLOAD option
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Apr 5, 2024
1 parent 12f2545 commit ac817d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn get_expected_sha256() -> Result<sha256::Hash, ()> {
}

fn main() {
if !HAS_FEATURE {
if !HAS_FEATURE || std::env::var_os("ELECTRUMD_SKIP_DOWNLOAD").is_some() {
return;
}
let download_filename = download_filename();
Expand Down
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"),
}
}
}
Expand Down Expand Up @@ -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<String, Error> {
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)
}
}

Expand All @@ -318,7 +323,9 @@ pub fn exe_path() -> Result<String, Error> {
(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!(),
}
}

Expand Down

0 comments on commit ac817d5

Please sign in to comment.