address rightward drift

This commit is contained in:
Robert Habermeier 2017-02-27 19:02:16 +01:00
parent da3c13f0a2
commit b487f00173

View File

@ -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. // completely in-place migration leads to the paths being equal.
// in that case, no need to shuffle directories. // in that case, no need to shuffle directories.
if temp_path != db_path { if temp_path == db_path { return Ok(()) }
// create backup
fs::rename(&db_path, &backup_path)?;
// replace the old database with the new one // create backup
if let Err(err) = fs::rename(&temp_path, &db_path) { fs::rename(&db_path, &backup_path)?;
// if something went wrong, bring back backup
fs::rename(&backup_path, &db_path)?;
return Err(err.into());
}
// remove backup // replace the old database with the new one
fs::remove_dir_all(&backup_path)?; 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 { fn exists(path: &Path) -> bool {