From d022e0304ffb61ac32891bc097be4abf11025a92 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 7 Nov 2018 20:57:21 -0500 Subject: don't even try to do work if we know there's nothing to do --- src/cmd/sync.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cmd/sync.rs b/src/cmd/sync.rs index 7dfb559..985b221 100644 --- a/src/cmd/sync.rs +++ b/src/cmd/sync.rs @@ -15,16 +15,18 @@ pub fn run(opts: &cli::Options) -> failure::Fallible<()> { let from = db.most_recent_timestamp()?.map(|x| x + 1); let to_fetch = lastfm.track_count(from)?; - let bar = indicatif::ProgressBar::new(to_fetch); - bar.set_style( - indicatif::ProgressStyle::default_bar() - .progress_chars("=> ") - .template("Downloading {pos}/{len} tracks...\n{percent:>3}% [{wide_bar}] {eta:5}") - ); + if to_fetch > 0 { + let bar = indicatif::ProgressBar::new(to_fetch); + bar.set_style( + indicatif::ProgressStyle::default_bar() + .progress_chars("=> ") + .template("Downloading {pos}/{len} tracks...\n{percent:>3}% [{wide_bar}] {eta:5}") + ); - db.insert_tracks(bar.wrap_iter(lastfm.tracks(from)))?; + db.insert_tracks(bar.wrap_iter(lastfm.tracks(from)))?; - bar.finish_with_message("done"); + bar.finish_with_message("done"); + } Ok(()) } -- cgit v1.2.3