Skip to content

Commit

Permalink
Auto-rename of db_dir/mainnet to db_dir/bitcoin
Browse files Browse the repository at this point in the history
Since version 0.9 the `mainnet` subdir is called `bitcoin` we need to
rename it if auto reindex is specified to fulfill the purpose of auto
reindex. The logic in this change keeps the intention of disabled auto
reindex causing no changes.
  • Loading branch information
Kixunil committed Sep 29, 2021
1 parent 6fff80e commit 07df2e1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/bin/electrs.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@

use anyhow::{Context, Result};
use electrs::{server, Config, Rpc, Tracker};
use std::{io, fs};

fn main() -> Result<()> {
let config = Config::from_args();

match (config.network, config.auto_reindex, config.db_path.parent()) {
(bitcoin::Network::Bitcoin, true, Some(db_parent)) => {
let old_dir = db_parent.join("mainnet");
match fs::rename(&old_dir, &config.db_path) {
Ok(()) => (),
Err(error) if error.kind() == io::ErrorKind::NotFound => (),
Err(error) => return Err(error).with_context(|| format!("failed to rename the old directory ({}) to {}", old_dir.display(), config.db_path.display())),
}
},
(bitcoin::Network::Bitcoin, false, Some(db_parent)) => {
let old_dir = db_parent.join("mainnet");
match fs::metadata(&old_dir) {
Ok(_) => anyhow::bail!("The old directory {} exists but auto reindex was disabled", old_dir.display()),
Err(error) if error.kind() == io::ErrorKind::NotFound => (),
Err(error) => return Err(error).with_context(|| format!("failed to check whether the old directory ({}) exists", old_dir.display())),
}
},
_ => (),
}

let rpc = Rpc::new(&config, Tracker::new(&config)?)?;
if config.sync_once {
return Ok(());
Expand Down

0 comments on commit 07df2e1

Please sign in to comment.