No longer clobbering broken files (re #14)

This commit is contained in:
Dennis Schwerdel 2017-04-17 15:42:06 +02:00
parent 150278a560
commit bd23aac64c
3 changed files with 16 additions and 4 deletions

View File

@ -15,6 +15,7 @@ This project follows [semantic versioning](http://semver.org).
* [fixed] Only repairing backups with --repair * [fixed] Only repairing backups with --repair
* [fixed] Fixed vacuum * [fixed] Fixed vacuum
* [fixed] First removing bundles, then adding new ones * [fixed] First removing bundles, then adding new ones
* [fixed] No longer clobbering broken files
### v0.2.0 (2017-04-14) ### v0.2.0 (2017-04-14)

View File

@ -348,9 +348,15 @@ impl BundleDb {
} }
fn evacuate_broken_bundle(&mut self, mut bundle: StoredBundle) -> Result<(), BundleDbError> { 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")); let src = self.layout.base_path().join(&bundle.path);
warn!("Moving bundle to {:?}", new_path); let mut dst = src.with_extension("bundle.broken");
try!(bundle.move_to(self.layout.base_path(), new_path)); 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); self.remote_bundles.remove(&bundle.info.id);
Ok(()) Ok(())
} }

View File

@ -159,7 +159,12 @@ impl Repository {
fn evacuate_broken_backup(&self, name: &str) -> Result<(), RepositoryError> { fn evacuate_broken_backup(&self, name: &str) -> Result<(), RepositoryError> {
warn!("The backup {} was corrupted and needed to be modified.", name); warn!("The backup {} was corrupted and needed to be modified.", name);
let src = self.layout.backup_path(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() { if fs::rename(&src, &dst).is_err() {
try!(fs::copy(&src, &dst)); try!(fs::copy(&src, &dst));
try!(fs::remove_file(&src)); try!(fs::remove_file(&src));