diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-04-09 10:34:58 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-04-09 10:34:58 +0200 |
commit | f718a548ea18d51925c8f361bb709927726dd6bc (patch) | |
tree | 2e1cf79b0a99fa6fca494087a05eef70c1b99f5a | |
parent | 5c36c119f9448baf6bfe5245c6ebac1aa09d5b43 (diff) | |
parent | 1e6f780bea00c1ef8cfe15350a7613d6aad67832 (diff) |
Merge branch 'source-simplify-impl'
-rw-r--r-- | src/commands/source.rs | 9 | ||||
-rw-r--r-- | src/source/mod.rs | 24 |
2 files changed, 13 insertions, 20 deletions
diff --git a/src/commands/source.rs b/src/commands/source.rs index 7f4a1bb..f194134 100644 --- a/src/commands/source.rs +++ b/src/commands/source.rs @@ -154,7 +154,7 @@ pub async fn list_missing(_: &ArgMatches, config: &Configuration, repo: Reposito repo.packages().try_for_each(|p| { for source in sc.sources_for(p) { - if !source.exists() { + if !source.path().exists() { writeln!( outlock, "{} {} -> {}", @@ -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.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.exists() && !force { + if source_path_exists && !force { Err(anyhow!("Source exists: {}", source.path().display())) } else { - if source.exists() { + if source_path_exists { let _ = source.remove_file().await?; } diff --git a/src/source/mod.rs b/src/source/mod.rs index ec0e2e2..7b84c30 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -47,14 +47,6 @@ pub struct SourceEntry { } impl SourceEntry { - fn source_file_path(&self) -> PathBuf { - self.source_file_directory().join(format!( - "{}-{}.source", - self.package_source_name, - self.package_source.hash().value() - )) - } - fn source_file_directory(&self) -> PathBuf { self.cache_root .join(format!("{}-{}", self.package_name, self.package_version)) @@ -75,12 +67,12 @@ impl SourceEntry { .collect() } - pub fn exists(&self) -> bool { - self.source_file_path().exists() - } - pub fn path(&self) -> PathBuf { - self.source_file_path() + self.source_file_directory().join(format!( + "{}-{}.source", + self.package_source_name, + self.package_source.hash().value() + )) } pub fn url(&self) -> &Url { @@ -92,13 +84,13 @@ impl SourceEntry { } pub async fn remove_file(&self) -> Result<()> { - let p = self.source_file_path(); + let p = self.path(); tokio::fs::remove_file(&p).await?; Ok(()) } pub async fn verify_hash(&self) -> Result<()> { - let p = self.source_file_path(); + let p = self.path(); trace!("Verifying : {}", p.display()); let reader = tokio::fs::OpenOptions::new() @@ -118,7 +110,7 @@ impl SourceEntry { } pub async fn create(&self) -> Result<tokio::fs::File> { - let p = self.source_file_path(); + let p = self.path(); trace!("Creating source file: {}", p.display()); if !self.cache_root.is_dir() { |