Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix task cache recursion into .pixi folder #2205

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/task/file_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use ignore::{overrides::OverrideBuilder, WalkBuilder};
use itertools::Itertools;
use pixi_consts::consts::PIXI_DIR;
use std::hash::Hash;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -95,6 +96,8 @@ impl FileHashes {
}
ignore_builder.add(&pat)?;
}
// Do not recurse into the .pixi directory
ignore_builder.add(&format!("!/{PIXI_DIR}"))?;

let filter = ignore_builder.build()?;

Expand All @@ -105,20 +108,23 @@ impl FileHashes {

// Iterate over all entries in parallel and send them over a channel to the collection thread.
let collect_root = root.to_owned();
println!("Collecting hashes for files in {:?}", root);
WalkBuilder::new(root)
.overrides(filter)
.hidden(false)
.git_ignore(false)
.git_global(false)
.git_exclude(false)
.follow_links(true)
.parents(false)
.build_parallel()
.run(|| {
let tx = tx.clone();
let collect_root = collect_root.clone();
Box::new(move |entry| {
let result = match entry {
Ok(entry) if entry.file_type().map(|t| t.is_dir()).unwrap_or(false) => {
tracing::info!("Recursing into directory: {:?}", entry.path());
return ignore::WalkState::Continue;
}
Ok(entry) => compute_file_hash(entry.path()).map(|hash| {
Expand All @@ -129,7 +135,34 @@ impl FileHashes {
tracing::info!("Added hash for file: {:?}", path);
(path.to_owned(), hash)
}),
Err(e) => Err(FileHashesError::from(e)),
Err(e) => {
// Special handling of broken symlinks
match e {
ignore::Error::WithPath { path, err } => {
match err.as_ref() {
ignore::Error::Io(io_err)
if io_err.kind() == std::io::ErrorKind::NotFound =>
{
// Ignore broken symlinks
tracing::info!("Skipping broken symlink: {:?}", path);
return ignore::WalkState::Continue;
}
_ => Err(FileHashesError::from(ignore::Error::WithPath {
path,
err,
})),
}
}
ignore::Error::Io(io_err)
if io_err.kind() == std::io::ErrorKind::NotFound =>
{
// Ignore broken symlinks
tracing::info!("Skipping broken symlink: {:?}", io_err);
return ignore::WalkState::Continue;
}
_ => Err(FileHashesError::from(e)),
}
}
};
match (result.is_err(), tx.send(result)) {
(true, _) => ignore::WalkState::Quit,
Expand Down
Loading