stronger checks

This commit is contained in:
Cyryl Płotnicki 2020-11-08 18:04:48 +00:00
parent d706826279
commit de6705c0fc
4 changed files with 7 additions and 11 deletions

View file

@ -7,6 +7,6 @@ fi
cargo fmt -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo check
cargo check --frozen
cargo test
cargo test -- --ignored

View file

@ -55,7 +55,7 @@ impl Index {
fs::create_dir_all(
path.as_ref()
.parent()
.ok_or(anyhow!("cannot compute parent path for {}", path.as_ref().to_string_lossy()))?,
.ok_or_else(|| anyhow!("cannot compute parent path for {}", path.as_ref().to_string_lossy()))?,
)
.context("create index directory")?;
@ -108,10 +108,7 @@ impl Index {
Ok(self
.index_file_path()
.parent()
.ok_or(anyhow!(
"cannot compute parent path for {}",
self.index_file_path().to_string_lossy()
))?
.ok_or_else(|| anyhow!("cannot compute parent path for {}", self.index_file_path().to_string_lossy()))?
.to_path_buf())
}
}

View file

@ -113,10 +113,9 @@ impl<'a> Repository<'a> {
let destination_path = Path::new(&destination_path);
if source_path.is_file() {
let parent = destination_path.parent().ok_or(anyhow!(
"cannot compute parent path for {}",
&destination_path.to_string_lossy()
))?;
let parent = destination_path
.parent()
.ok_or_else(|| anyhow!("cannot compute parent path for {}", &destination_path.to_string_lossy()))?;
fs::create_dir_all(parent)?;
fs::copy(source_path, destination_path)?;
let relative_path = destination_path.strip_prefix(self.path)?;

View file

@ -36,7 +36,7 @@ impl RepositoryItem {
}
let parent = target_path
.parent()
.ok_or(anyhow!("cannot compute parent path for {}", &target_path.to_string_lossy()))?;
.ok_or_else(|| anyhow!("cannot compute parent path for {}", &target_path.to_string_lossy()))?;
if !parent.exists() {
fs::create_dir_all(parent)?;
}