Skip to content

Commit

Permalink
allow to resolve symlinks on DirectoryEntry (vercel/turborepo#8851)
Browse files Browse the repository at this point in the history
### Description

Just a little helper method to resolve symlinks when doing `read_dir`

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
sokra authored Jul 29, 2024
1 parent 484f244 commit 3793f6a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/turbo-tasks-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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 {
Expand Down

0 comments on commit 3793f6a

Please sign in to comment.