Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ELECTRUMD_SKIP_DOWNLOAD option #1

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading