Skip to content

Commit

Permalink
fix(save): refresh the catalog before compacting
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Aug 18, 2022
1 parent 23c5db9 commit f85458c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ async fn run(config: Config) {
// In practice this should never fail: write to the catalog already ensures
// the catalog's dirpath is writable.
catalog
.refresh()
.await
.expect("Success saving but could not refresh")
.compact()
.await
.expect("Success saving but could not compact");
Expand Down
10 changes: 10 additions & 0 deletions src/management/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ impl Catalog {
Ok(catalog)
}

/// Update the catalog's list of backups with current content of `dirpath`.
pub async fn refresh(self) -> Result<Catalog> {
let backups = Self::read_files(self.dirpath.as_path()).await?;
Ok(Catalog {
dirpath: self.dirpath,
strategy: self.strategy,
backups,
})
}

/// Update the catalog's list of backups with current content of `dirpath`.
pub async fn refresh_mut(&mut self) -> Result<()> {
self.backups = Self::read_files(self.dirpath.as_path()).await?;
Expand Down

0 comments on commit f85458c

Please sign in to comment.