+ // Make a backup of the database.
+ let db_path = Path::new(consts::DB_DIRECTORY).join(consts::DB_FILENAME);
+ if db_path.exists() {
+ let db_path_bckup = (1..)
+ .find_map(|n| {
+ let p = db_path.with_extension(format!("sqlite.bckup{:03}", n));
+ if p.exists() {
+ None
+ } else {
+ Some(p)
+ }
+ })
+ .unwrap();
+ std::fs::copy(&db_path, &db_path_bckup).expect(&format!(
+ "Unable to make backup of {:?} to {:?}",
+ &db_path, &db_path_bckup
+ ));
+ std::fs::remove_file(&db_path)
+ .expect(&format!("Unable to remove db file: {:?}", &db_path));
+ }
+