summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-08 20:29:40 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-08 20:55:09 +0200
commitcbdea0872d4e3f12ce08546667daa6015d0c087b (patch)
tree48f0ee0b5f5ee12c1d460ed844a85eb92ec9c448
parentbaa820c60675f84ed0652f0b11feefe9230a97a1 (diff)
Optimize: Dont compute PathBuf object three times
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/commands/source.rs7
1 files 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?;
}