mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(resolver): use fs::symlink_metadata, which doesn't traverse symlinks (#581)
This commit is contained in:
parent
a27b60cfb4
commit
3c5333c828
3 changed files with 10 additions and 6 deletions
|
|
@ -36,7 +36,7 @@ impl<Fs: FileSystem> Cache<Fs> {
|
|||
if let Some(result) = self.cache.get(path) {
|
||||
return *result;
|
||||
}
|
||||
let file_metadata = self.fs.metadata(path).ok();
|
||||
let file_metadata = self.fs.symlink_metadata(path).ok();
|
||||
self.cache.insert(path.to_path_buf().into_boxed_path(), file_metadata);
|
||||
file_metadata
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@ pub trait FileSystem: Default + Send + Sync {
|
|||
|
||||
/// # Errors
|
||||
///
|
||||
/// * Any [io::Error]
|
||||
fn metadata<P: AsRef<Path>>(&self, path: P) -> io::Result<FileMetadata>;
|
||||
/// This function will return an error in the following situations, but is not
|
||||
/// limited to just these cases:
|
||||
///
|
||||
/// * The user lacks permissions to perform `metadata` call on `path`.
|
||||
/// * `path` does not exist.
|
||||
fn symlink_metadata<P: AsRef<Path>>(&self, path: P) -> io::Result<FileMetadata>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
@ -32,7 +36,7 @@ impl FileSystem for FileSystemOs {
|
|||
fs::read_to_string(path)
|
||||
}
|
||||
|
||||
fn metadata<P: AsRef<Path>>(&self, path: P) -> io::Result<FileMetadata> {
|
||||
fs::metadata(path).map(|metadata| FileMetadata { is_file: metadata.is_file() })
|
||||
fn symlink_metadata<P: AsRef<Path>>(&self, path: P) -> io::Result<FileMetadata> {
|
||||
fs::symlink_metadata(path).map(|metadata| FileMetadata { is_file: metadata.is_file() })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ impl FileSystem for MemoryFS {
|
|||
Ok(buffer)
|
||||
}
|
||||
|
||||
fn metadata<P: AsRef<Path>>(&self, path: P) -> io::Result<FileMetadata> {
|
||||
fn symlink_metadata<P: AsRef<Path>>(&self, path: P) -> io::Result<FileMetadata> {
|
||||
use vfs::FileSystem;
|
||||
let metadata = self
|
||||
.fs
|
||||
|
|
|
|||
Loading…
Reference in a new issue