Skip to content

Commit

Permalink
refactor(utils): make ignore_path optional
Browse files Browse the repository at this point in the history
  • Loading branch information
beeb committed Aug 6, 2024
1 parent 401fe4d commit ce11f4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dependency_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn unzip_dependency(dependency: &HttpDependency) -> Result<IntegrityChecksum
zip_extract::extract(Cursor::new(zip_contents), &target_dir, true)?;
println!("{}", format!("The dependency {dependency} was unzipped!").green());

hash_folder(&target_dir, zip_path)
hash_folder(&target_dir, Some(zip_path))
.map_err(|e| DownloadError::IOError { path: target_dir, source: e })
}

Expand Down
15 changes: 9 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ pub fn hash_content<R: Read>(content: &mut R) -> [u8; 32] {
/// file right after unzipping so this is not necessary?
pub fn hash_folder(
folder_path: impl AsRef<Path>,
ignore_path: PathBuf,
ignore_path: Option<PathBuf>,
) -> Result<IntegrityChecksum, std::io::Error> {
// perf: it's easier to check a boolean than to compare paths, so when we find the zip we skip
// the check afterwards
let seen_ignore_path = Arc::new(AtomicBool::new(false));
let seen_ignore_path = Arc::new(AtomicBool::new(ignore_path.is_none()));
// a list of hashes, one for each DirEntry
let hashes = Arc::new(Mutex::new(Vec::with_capacity(100)));
// we use a parallel walker to speed things up
Expand All @@ -216,10 +216,13 @@ pub fn hash_folder(
};
let path = entry.path();
// check if that file is `ignore_path`, unless we've seen it already
if !seen_ignore_path.load(Ordering::SeqCst) && path == ignore_path {
// record that we've seen the zip file
seen_ignore_path.swap(true, Ordering::SeqCst);
return WalkState::Continue;
if !seen_ignore_path.load(Ordering::SeqCst) {
let ignore_path = ignore_path.as_ref().unwrap();
if path == ignore_path {
// record that we've seen the zip file
seen_ignore_path.swap(true, Ordering::SeqCst);
return WalkState::Continue;
}
}
// first hash the filename/dirname to make sure it can't be renamed or removed
let mut hasher = <Sha256 as Digest>::new();
Expand Down

0 comments on commit ce11f4c

Please sign in to comment.