From bd23aac64c5e5342b9b7376e22afb6e69ed52291 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Mon, 17 Apr 2017 15:42:06 +0200 Subject: [PATCH] No longer clobbering broken files (re #14) --- CHANGELOG.md | 1 + src/bundledb/db.rs | 12 +++++++++--- src/repository/integrity.rs | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260927b..b4d19a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project follows [semantic versioning](http://semver.org). * [fixed] Only repairing backups with --repair * [fixed] Fixed vacuum * [fixed] First removing bundles, then adding new ones +* [fixed] No longer clobbering broken files ### v0.2.0 (2017-04-14) diff --git a/src/bundledb/db.rs b/src/bundledb/db.rs index e24ff47..4305a7b 100644 --- a/src/bundledb/db.rs +++ b/src/bundledb/db.rs @@ -348,9 +348,15 @@ impl BundleDb { } fn evacuate_broken_bundle(&mut self, mut bundle: StoredBundle) -> Result<(), BundleDbError> { - let new_path = self.layout.base_path().join(bundle.path.with_extension("bundle.broken")); - warn!("Moving bundle to {:?}", new_path); - try!(bundle.move_to(self.layout.base_path(), new_path)); + let src = self.layout.base_path().join(&bundle.path); + let mut dst = src.with_extension("bundle.broken"); + let mut num = 1; + while dst.exists() { + dst = src.with_extension(&format!("bundle.{}.broken", num)); + num += 1; + } + warn!("Moving bundle to {:?}", dst); + try!(bundle.move_to(self.layout.base_path(), dst)); self.remote_bundles.remove(&bundle.info.id); Ok(()) } diff --git a/src/repository/integrity.rs b/src/repository/integrity.rs index e19abde..51b7b23 100644 --- a/src/repository/integrity.rs +++ b/src/repository/integrity.rs @@ -159,7 +159,12 @@ impl Repository { fn evacuate_broken_backup(&self, name: &str) -> Result<(), RepositoryError> { warn!("The backup {} was corrupted and needed to be modified.", name); let src = self.layout.backup_path(name); - let dst = src.with_extension("backup.broken"); + let mut dst = src.with_extension("backup.broken"); + let mut num = 1; + while dst.exists() { + dst = src.with_extension(&format!("backup.{}.broken", num)); + num += 1; + } if fs::rename(&src, &dst).is_err() { try!(fs::copy(&src, &dst)); try!(fs::remove_file(&src));