From b487f001734ac588feac0b0138d57fae1531da5b Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Mon, 27 Feb 2017 19:02:16 +0100 Subject: [PATCH] address rightward drift --- parity/migration.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/parity/migration.rs b/parity/migration.rs index 0d99bf250..445724325 100644 --- a/parity/migration.rs +++ b/parity/migration.rs @@ -203,22 +203,20 @@ fn migrate_database(version: u32, db_path: PathBuf, mut migrations: MigrationMan // completely in-place migration leads to the paths being equal. // in that case, no need to shuffle directories. - if temp_path != db_path { - // create backup - fs::rename(&db_path, &backup_path)?; + if temp_path == db_path { return Ok(()) } - // replace the old database with the new one - if let Err(err) = fs::rename(&temp_path, &db_path) { - // if something went wrong, bring back backup - fs::rename(&backup_path, &db_path)?; - return Err(err.into()); - } + // create backup + fs::rename(&db_path, &backup_path)?; - // remove backup - fs::remove_dir_all(&backup_path)?; + // replace the old database with the new one + if let Err(err) = fs::rename(&temp_path, &db_path) { + // if something went wrong, bring back backup + fs::rename(&backup_path, &db_path)?; + return Err(err.into()); } - Ok(()) + // remove backup + fs::remove_dir_all(&backup_path).map_err(Into::into) } fn exists(path: &Path) -> bool {