Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
ensure the target folder doesn't exist before renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed Sep 13, 2016
1 parent dcfd7ea commit b9159c7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions ethcore/src/snapshot/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ impl Service {
// destroy the old snapshot reader.
*reader = None;

if snapshot_dir.exists() {
try!(fs::remove_dir_all(&snapshot_dir));
}

try!(fs::rename(temp_dir, &snapshot_dir));

*reader = Some(try!(LooseReader::new(snapshot_dir)));
Expand Down Expand Up @@ -428,16 +432,11 @@ impl Service {

let snapshot_dir = self.snapshot_dir();

trace!(target: "snapshot", "removing old snapshot dir at {}", snapshot_dir.to_string_lossy());
if let Err(e) = fs::remove_dir_all(&snapshot_dir) {
match e.kind() {
ErrorKind::NotFound => {}
_ => return Err(e.into()),
}
if snapshot_dir.exists() {
trace!(target: "snapshot", "removing old snapshot dir at {}", snapshot_dir.to_string_lossy());
try!(fs::remove_dir_all(&snapshot_dir));
}

try!(fs::create_dir(&snapshot_dir));

trace!(target: "snapshot", "copying restored snapshot files over");
try!(fs::rename(self.temp_recovery_dir(), &snapshot_dir));

Expand Down

0 comments on commit b9159c7

Please sign in to comment.