Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle the case where the repository has no snapshots #46

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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