From cbdea0872d4e3f12ce08546667daa6015d0c087b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 8 Apr 2021 20:29:40 +0200 Subject: Optimize: Dont compute PathBuf object three times Signed-off-by: Matthias Beyer --- src/commands/source.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/source.rs b/src/commands/source.rs index 50f6a30..f194134 100644 --- a/src/commands/source.rs +++ b/src/commands/source.rs @@ -244,7 +244,8 @@ pub async fn download( let bar = multi.add(progressbars.spinner()); bar.set_message(&format!("Downloading {}", source.url())); async move { - if !source.path().exists() && source.download_manually() { + let source_path_exists = source.path().exists(); + if !source_path_exists && source.download_manually() { return Err(anyhow!( "Cannot download source that is marked for manual download" )) @@ -253,10 +254,10 @@ pub async fn download( .map_err(Error::from); } - if source.path().exists() && !force { + if source_path_exists && !force { Err(anyhow!("Source exists: {}", source.path().display())) } else { - if source.path().exists() { + if source_path_exists { let _ = source.remove_file().await?; } -- cgit v1.2.3