Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions crates/vite_task/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{ffi::OsString, io, path::Path, sync::Arc};
use std::{ffi::OsString, io, path::Path};

use fspy::error::SpawnError;
use petgraph::algo::Cycle;
use vite_path::{
AbsolutePath, RelativePathBuf,
RelativePathBuf,
absolute::StripPrefixError,
relative::{FromPathError, InvalidPathDataError},
};
Expand Down Expand Up @@ -54,9 +54,6 @@ pub enum Error {
#[error("The path ({path:?}) is not a valid relative path because: {reason}")]
InvalidRelativePath { path: Box<Path>, reason: FromPathError },

#[error("IO error: {err} at {path:?}")]
IoWithPath { err: io::Error, path: Arc<AbsolutePath> },

#[cfg(unix)]
#[error("Unsupported file type: {0:?}")]
UnsupportedFileType(nix::dir::Type),
Expand Down
24 changes: 12 additions & 12 deletions crates/vite_task/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn hash_content(mut stream: impl Read) -> io::Result<u64> {
}

impl FileSystem for RealFileSystem {
#[tracing::instrument(level = "trace")]
fn fingerprint_path(
&self,
path: &Arc<AbsolutePath>,
Expand All @@ -49,6 +50,7 @@ impl FileSystem for RealFileSystem {

let file = match File::open(std_path) {
Ok(file) => file,
#[allow(unused)]
Err(err) => {
// On Windows, File::open fails specifically for directories with PermissionDenied
#[cfg(windows)]
Expand All @@ -58,18 +60,16 @@ impl FileSystem for RealFileSystem {
return RealFileSystem::process_directory(std_path, path_read);
}
}

return if matches!(
err.kind(),
io::ErrorKind::NotFound |
// A component used as a directory in path is not a directory,
// e.g. "/foo.txt/bar" where "/foo.txt" is a file
io::ErrorKind::NotADirectory
) {
Ok(PathFingerprint::NotFound)
} else {
Err(Error::IoWithPath { err, path: path.clone() })
};
if err.kind() != io::ErrorKind::NotFound {
tracing::trace!(
"Uncommon error when opening {:?} for fingerprinting: {}",
std_path,
err
);
}
// There are many reasons why opening a file might fail (NotFound, InvalidFilename, NotADirectory, PermissionDenied).
// Consider all of them as NotFound for fingerprinting purposes.
return Ok(PathFingerprint::NotFound);
}
};

Expand Down