From ec731576347ed602632b6b014855372e1e1b28ee Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 26 Jul 2024 15:37:07 +0200 Subject: [PATCH] allow to resolve symlinks on DirectoryEntry --- crates/turbo-tasks-fs/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/turbo-tasks-fs/src/lib.rs b/crates/turbo-tasks-fs/src/lib.rs index ce8bac17528162..5b84cca255cde6 100644 --- a/crates/turbo-tasks-fs/src/lib.rs +++ b/crates/turbo-tasks-fs/src/lib.rs @@ -1807,6 +1807,24 @@ pub enum DirectoryEntry { Error, } +/// Handles the `DirectoryEntry::Symlink` variant by checking the symlink target +/// type and replacing it with `DirectoryEntry::File` or +/// `DirectoryEntry::Directory`. +impl DirectoryEntry { + pub async fn resolve_symlink(self) -> Result { + if let DirectoryEntry::Symlink(symlink) = self { + let real_path = symlink.realpath().resolve().await?; + match *real_path.get_type().await? { + FileSystemEntryType::Directory => Ok(DirectoryEntry::Directory(real_path)), + FileSystemEntryType::File => Ok(DirectoryEntry::File(real_path)), + _ => Ok(self), + } + } else { + Ok(self) + } + } +} + #[turbo_tasks::value] #[derive(Hash, Clone, Copy, Debug)] pub enum FileSystemEntryType {