Skip to content

Commit ac817d5

Browse files
committed
Add ELECTRUMD_SKIP_DOWNLOAD option
Context: Blockstream/electrs#73
1 parent 12f2545 commit ac817d5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn get_expected_sha256() -> Result<sha256::Hash, ()> {
2121
}
2222

2323
fn main() {
24-
if !HAS_FEATURE {
24+
if !HAS_FEATURE || std::env::var_os("ELECTRUMD_SKIP_DOWNLOAD").is_some() {
2525
return;
2626
}
2727
let download_filename = download_filename();

src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum Error {
6868
NeitherFeatureNorEnvVar,
6969
/// Returned when calling methods requiring either a feature or anv var, but both are present
7070
BothFeatureAndEnvVar,
71+
/// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set
72+
SkipDownload,
7173
}
7274

7375
impl fmt::Debug for Error {
@@ -81,6 +83,7 @@ impl fmt::Debug for Error {
8183
Error::NoEnvVar => write!(f, "Called a method requiring env var `ELECTRUMD_EXE` to be set, but it's not"),
8284
Error::NeitherFeatureNorEnvVar => write!(f, "Called a method requiring env var `ELECTRUMD_EXE` or a feature to be set, but neither are set"),
8385
Error::BothFeatureAndEnvVar => write!(f, "Called a method requiring env var `ELECTRUMD_EXE` or a feature to be set, but both are set"),
86+
Error::SkipDownload => write!(f, "expecting an auto-downloaded executable but `ELECTRUMD_SKIP_DOWNLOAD` env var is set"),
8487
}
8588
}
8689
}
@@ -300,14 +303,16 @@ fn rand_string() -> String {
300303

301304
/// Provide the electrum executable path if a version feature has been specified
302305
pub fn downloaded_exe_path() -> Result<String, Error> {
303-
if versions::HAS_FEATURE {
306+
if std::env::var_os("ELECTRUMD_SKIP_DOWNLOAD").is_some() {
307+
Err(Error::SkipDownload)
308+
} else if !versions::HAS_FEATURE {
309+
Err(Error::NoFeature)
310+
} else {
304311
Ok(format!(
305312
"{}/electrum/electrum-{}/electrum.AppImage",
306313
env!("OUT_DIR"),
307314
versions::VERSION
308315
))
309-
} else {
310-
Err(Error::NoFeature)
311316
}
312317
}
313318

@@ -318,7 +323,9 @@ pub fn exe_path() -> Result<String, Error> {
318323
(Ok(_), Ok(_)) => Err(Error::BothFeatureAndEnvVar),
319324
(Ok(path), Err(_)) => Ok(path),
320325
(Err(_), Ok(path)) => Ok(path),
321-
(Err(_), Err(_)) => Err(Error::NeitherFeatureNorEnvVar),
326+
(Err(Error::NoFeature), Err(_)) => Err(Error::NeitherFeatureNorEnvVar),
327+
(Err(Error::SkipDownload), Err(_)) => Err(Error::SkipDownload),
328+
(Err(_), Err(_)) => unreachable!(),
322329
}
323330
}
324331

0 commit comments

Comments
 (0)