Skip to content

Commit

Permalink
gracefully handle the case where the repository has no snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
drdo committed Jul 20, 2024
1 parent abe1bf4 commit 49591dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ impl Cache {
})
.intersperse(String::from(" UNION ALL "))
.collect::<String>();
if cte_stmt_string.is_empty() {
return Ok(vec![]);
}
let mut stmt = self.conn.prepare(&format!(
"WITH rich_entries AS ({cte_stmt_string}) \
SELECT \
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ fn main() -> anyhow::Result<()> {

sync_snapshots(&restic, &mut cache, cli.fetching_thread_count)?;

let entries = cache.get_entries(None)?;
if entries.is_empty() {
eprintln!("The repository has no snapshots!");
return Ok(());
}

// UI
stderr().execute(EnterAlternateScreen)?;
panic::update_hook(|prev, info| {
Expand All @@ -197,7 +203,7 @@ fn main() -> anyhow::Result<()> {
rect.as_size(),
None,
Utf8PathBuf::new(),
cache.get_entries(None)?,
entries,
cache.get_marks().unwrap(),
vec![
"Enter".bold(),
Expand Down Expand Up @@ -310,6 +316,7 @@ fn sync_snapshots(
})
.collect();
missing_snapshots.shuffle(&mut thread_rng());
missing_snapshots = vec![];
let total_missing_snapshots = match missing_snapshots.len() {
0 => {
eprintln!("Snapshots up to date");
Expand Down

0 comments on commit 49591dc

Please sign in to comment.