Unverified Commit b2e835de authored by Benjamin Woodruff ‮'s avatar Benjamin Woodruff Committed by GitHub

Turbopack: Split the read and write codepath data structures for symlinks (#97395)

Another attempt at cleanup, similar to
https://github.com/vercel/next.js/pull/96955.

We need different information to write symlinks or junction points (most
notably, if it's a directory or not) than we get when reading symlinks.

We were trying to use the same data structure for both, but this lead us
to always call `get_type()` as part of reading a link, which was just
silly.

This also meant that `write_link` had to handle `NotFound` and
`Invalid`. `NotFound` is somewhat reasonable (just delete the file), but
`Invalid` is awkward.
parent ee690921
...@@ -10260,6 +10260,7 @@ dependencies = [ ...@@ -10260,6 +10260,7 @@ dependencies = [
"turbo-unix-path", "turbo-unix-path",
"url", "url",
"urlencoding", "urlencoding",
"windows-sys 0.60.2",
] ]
[[package]] [[package]]
......
...@@ -361,6 +361,7 @@ unsize = "1.1.0" ...@@ -361,6 +361,7 @@ unsize = "1.1.0"
unty = "0.0.4" unty = "0.0.4"
url = "2.2.2" url = "2.2.2"
urlencoding = "2.1.2" urlencoding = "2.1.2"
windows-sys = "0.60"
uuid = "1.18.1" uuid = "1.18.1"
vergen = { version = "9.0.6", features = ["cargo"] } vergen = { version = "9.0.6", features = ["cargo"] }
vergen-gitcl = { version = "1.0.8", features = ["cargo"] } vergen-gitcl = { version = "1.0.8", features = ["cargo"] }
......
...@@ -285,22 +285,14 @@ async fn assets_diff( ...@@ -285,22 +285,14 @@ async fn assets_diff(
), ),
} }
} }
( (AssetContent::Redirect(content1), AssetContent::Redirect(content2)) => {
AssetContent::Redirect { if content1.target == content2.target && content1.target_type == content2.target_type {
target: target1,
link_type: link_type1,
},
AssetContent::Redirect {
target: target2,
link_type: link_type2,
},
) => {
if target1 == target2 && link_type1 == link_type2 {
None None
} else { } else {
Some(format!( Some(format!(
"assets at the same path are both redirects but point to different targets: \ "assets at the same path are both redirects but disagree: {:?} ({:?}) vs {:?} \
{target1} vs {target2}" ({:?})",
content1.target, content1.target_type, content2.target, content2.target_type,
)) ))
} }
} }
......
...@@ -58,9 +58,11 @@ use turbo_tasks::{ ...@@ -58,9 +58,11 @@ use turbo_tasks::{
unmark_top_level_task_may_leak_eventually_consistent_state, unmark_top_level_task_may_leak_eventually_consistent_state,
}; };
use turbo_tasks_backend::db_invalidation::invalidation_reasons; use turbo_tasks_backend::db_invalidation::invalidation_reasons;
#[cfg(windows)]
use turbo_tasks_fs::windows::to_verbatim_with_case_folded_disk;
use turbo_tasks_fs::{ use turbo_tasks_fs::{
DiskFileSystem, FileContent, FileSystem, FileSystemPath, canonicalize_to_rcstr, invalidation, DiskFileSystem, FileContent, FileSystem, FileSystemPath, canonicalize_to_rcstr, invalidation,
to_verbatim_with_case_folded_disk, util::uri_from_file, util::uri_from_file,
}; };
use turbo_unix_path::{get_relative_path_to, unix_to_sys}; use turbo_unix_path::{get_relative_path_to, unix_to_sys};
use turbopack_core::{ use turbopack_core::{
...@@ -2385,9 +2387,12 @@ fn parse_and_canonicalize_source_url(source_url: &str) -> Result<(RcStr, Option< ...@@ -2385,9 +2387,12 @@ fn parse_and_canonicalize_source_url(source_url: &str) -> Result<(RcStr, Option<
Err(_) => { Err(_) => {
// The file may not exist (e.g. a stale stack frame). Fall back to a purely lexical // The file may not exist (e.g. a stale stack frame). Fall back to a purely lexical
// normalization that approximates the canonical format. // normalization that approximates the canonical format.
if cfg!(windows) { #[cfg(windows)]
{
to_verbatim_with_case_folded_disk(&path).unwrap_or(path) to_verbatim_with_case_folded_disk(&path).unwrap_or(path)
} else { }
#[cfg(not(windows))]
{
path path
} }
} }
......
...@@ -59,6 +59,11 @@ urlencoding = { workspace = true } ...@@ -59,6 +59,11 @@ urlencoding = { workspace = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
omnipath = "0.1.6" omnipath = "0.1.6"
windows-sys = { workspace = true, features = [
"Win32_Foundation",
"Win32_Storage_FileSystem",
"Win32_System_SystemServices",
] }
[dev-dependencies] [dev-dependencies]
criterion = { workspace = true, features = ["async_tokio"] } criterion = { workspace = true, features = ["async_tokio"] }
...@@ -68,4 +73,3 @@ sha2 = { workspace = true } ...@@ -68,4 +73,3 @@ sha2 = { workspace = true }
tempfile = { workspace = true } tempfile = { workspace = true }
turbo-tasks-testing = { workspace = true } turbo-tasks-testing = { workspace = true }
turbo-tasks-backend = { workspace = true } turbo-tasks-backend = { workspace = true }
...@@ -10,7 +10,6 @@ use std::{ ...@@ -10,7 +10,6 @@ use std::{
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use bitflags::bitflags;
use jsonc_parser::{ParseOptions, parse_to_serde_value}; use jsonc_parser::{ParseOptions, parse_to_serde_value};
use mime::Mime; use mime::Mime;
use serde_json::Value; use serde_json::Value;
...@@ -21,6 +20,7 @@ use turbo_tasks_hash::{ ...@@ -21,6 +20,7 @@ use turbo_tasks_hash::{
}; };
use crate::{ use crate::{
FileSystemEntryType, FileSystemPath,
json::UnparsableJson, json::UnparsableJson,
retry::retry_blocking, retry::retry_blocking,
rope::{Rope, RopeReader}, rope::{Rope, RopeReader},
...@@ -163,47 +163,69 @@ pub(crate) enum FileComparison { ...@@ -163,47 +163,69 @@ pub(crate) enum FileComparison {
NotEqual, NotEqual,
} }
bitflags! { /// The target of a symbolic link, as read from a filesystem.
#[derive( ///
Default, /// Every variant carries the `resolved` path the link points at, computed once by
TraceRawVcs, /// [`crate::FileSystem::read_link`], which is also what guarantees the target stays inside the
NonLocalValue, /// filesystem root — a link whose target leaves the root is [`LinkContent::Invalid`] instead.
DeterministicHash, #[derive(Clone, Debug, Hash, PartialEq, Eq, TraceRawVcs, NonLocalValue, Encode, Decode)]
Encode, pub enum LinkTarget {
Decode, /// The link is an absolute path on disk.
)] Absolute { resolved: FileSystemPath },
pub struct LinkType: u8 { Relative {
const DIRECTORY = 0b00000001; /// The value read from the link. The path is lexically converted to a [unix-style
const ABSOLUTE = 0b00000010; /// path][turbo_unix_path::sys_to_unix], but it may contain `..` relative to the *directory
} /// containing the link*.
raw: RcStr,
/// The link target relative the a `DiskFileSystem` root.
resolved: FileSystemPath,
},
} }
/// The contents of a symbolic link. On Windows, this may be a junction point. impl LinkTarget {
/// The path this link points at.
pub fn file_system_path(&self) -> &FileSystemPath {
match self {
LinkTarget::Absolute { resolved } | LinkTarget::Relative { resolved, .. } => resolved,
}
}
/// The type of the file this link points at.
///
/// This only follows a single link: if the target is itself a symbolic link, this returns
/// [`FileSystemEntryType::Symlink`]. Use [`FileSystemPath::realpath`] to follow a chain of
/// links.
///
/// A dangling link returns [`FileSystemEntryType::NotFound`].
pub async fn target_type(&self) -> Result<FileSystemEntryType> {
Ok(*self.file_system_path().get_type().await?)
}
}
/// The contents of a symbolic link, as read from a filesystem. On Windows, this may be a junction
/// point.
///
/// We treat symbolic links and junction points on Windows as equivalent when reading.
/// ///
/// When reading, we treat symbolic links and junction points on Windows as equivalent. When /// This describes the link itself and never the type of the file it points at. Use
/// creating a new link, we always create junction points, because symlink creation may fail if /// [`LinkTarget::target_type`] if you need the type of the target.
/// Windows "developer mode" is not enabled and we're running in an unprivileged environment.
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Debug, DeterministicHash)] #[derive(Debug)]
pub enum LinkContent { pub enum LinkContent {
/// A valid symbolic link pointing to `target`, a unix-style path. /// A valid symbolic link pointing to `target`.
/// Link { target: LinkTarget },
/// If [`LinkType::ABSOLUTE`] is set, `target` is normalized and relative to the *filesystem /// The link itself does not exist at the path given to [`FileSystemPath::read_link`].
/// root* (so that absolute system paths never end up in the persistent cache). Otherwise,
/// `target` is the raw value read from the link — unnormalized, may contain `..` — and is
/// relative to the *directory containing the link*.
/// ///
/// A relative `target` must stay raw so that [`FileSystem::write_link`] round-trips it /// This says nothing about whether the link's target exists: a dangling link is still
/// exactly: the value is written verbatim and compared against [`std::fs::read_link`] to /// returned as [`LinkContent::Link`].
/// skip unchanged links.
Link {
target: RcStr,
link_type: LinkType,
},
// Invalid means the link is invalid it points out of the filesystem root
Invalid,
// The target was not found
NotFound, NotFound,
/// The link could not be read.
///
/// This includes all I/O errors other than `NotFound`, denied paths, and targets that leave the
/// filesystem root. A relative target that steps out of the root and back into it is also
/// invalid, since resolving it would need the names of the root's own ancestors, which a
/// root-relative path doesn't carry.
Invalid { reason: RcStr },
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -213,14 +235,70 @@ impl LinkContent { ...@@ -213,14 +235,70 @@ impl LinkContent {
/// re-create a symlink as a symlink instead of copying the resolved file. /// re-create a symlink as a symlink instead of copying the resolved file.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn hash(&self, salt: Vc<RcStr>, algorithm: HashAlgorithm) -> Result<Vc<RcStr>> { pub async fn hash(&self, salt: Vc<RcStr>, algorithm: HashAlgorithm) -> Result<Vc<RcStr>> {
#[derive(DeterministicHash)]
enum SimplifiedLinkContent<'a> {
Absolute(&'a RcStr),
Relative(&'a RcStr),
NotFound,
Invalid, // the actual error message doesn't matter for this API
}
let simplified = match self {
LinkContent::Link { target } => match target {
LinkTarget::Absolute { resolved } => {
SimplifiedLinkContent::Absolute(&resolved.path)
}
LinkTarget::Relative { raw, resolved: _ } => SimplifiedLinkContent::Relative(raw),
},
LinkContent::NotFound => SimplifiedLinkContent::NotFound,
LinkContent::Invalid { reason: _ } => SimplifiedLinkContent::Invalid,
};
Ok(Vc::cell(RcStr::from(deterministic_hash( Ok(Vc::cell(RcStr::from(deterministic_hash(
&salt.await?, &salt.await?,
self, simplified,
algorithm, algorithm,
)))) ))))
} }
} }
/// The target of a symbolic link to create, used by [`WriteLinkContent`].
///
/// Unlike [`LinkTarget`] this carries only the raw path: the write side never needs the target
/// resolved, and the link being created may not even exist yet.
#[derive(
Clone, Debug, Hash, PartialEq, Eq, TraceRawVcs, NonLocalValue, DeterministicHash, Encode, Decode,
)]
pub enum WriteLinkTarget {
/// Normalized and relative to the *filesystem root*.
Absolute(RcStr),
/// Written verbatim, relative to the *directory containing the link*.
Relative(RcStr),
}
/// The file type of the target of a newly written link. This value is only used on Windows.
#[derive(
Clone, Debug, Hash, PartialEq, Eq, TraceRawVcs, NonLocalValue, DeterministicHash, Encode, Decode,
)]
pub enum WriteLinkTargetType {
/// Represents a link to a file or a symbolic link that is not a junction point. This is likely
/// to fail on Windows, where symbolic links are not enabled by default.
FileNonPortable,
/// Represents a link to a directory. On Windows, this may also be a link to a junction point.
DirectoryOrJunctionPoint,
}
/// The symbolic link to create at a path, passed to [`FileSystemPath::write_link`].
///
/// This is separate from [`LinkContent`] because writing needs to know whether the target is a
/// directory, while reading a link does not: on Windows we always create junction points for
/// directories, because symlink creation may fail if "developer mode" is not enabled and we're
/// running in an unprivileged environment.
#[turbo_tasks::value(shared)]
#[derive(Clone, Debug, DeterministicHash)]
pub struct WriteLinkContent {
pub target: WriteLinkTarget,
pub target_type: WriteLinkTargetType,
}
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone, DeterministicHash, PartialOrd, Ord)] #[derive(Clone, DeterministicHash, PartialOrd, Ord)]
pub struct File { pub struct File {
......
This diff is collapsed.
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use auto_hash_map::AutoMap; use auto_hash_map::AutoMap;
use include_dir::{Dir, DirEntry}; use include_dir::{Dir, DirEntry};
use turbo_rcstr::RcStr; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ValueToString, Vc}; use turbo_tasks::{ValueToString, Vc};
use crate::{ use crate::{
File, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent, File, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
RawDirectoryEntry, RawDirectoryEntry, WriteLinkContent,
}; };
#[derive(ValueToString)] #[derive(ValueToString)]
...@@ -38,7 +38,15 @@ impl FileSystem for EmbeddedFileSystem { ...@@ -38,7 +38,15 @@ impl FileSystem for EmbeddedFileSystem {
#[turbo_tasks::function] #[turbo_tasks::function]
fn read_link(&self, _path: FileSystemPath) -> Vc<LinkContent> { fn read_link(&self, _path: FileSystemPath) -> Vc<LinkContent> {
LinkContent::NotFound.cell() LinkContent::Invalid {
reason: rcstr!("the filesystem does not support symbolic links"),
}
.cell()
}
#[turbo_tasks::function]
fn is_junction_point(&self, _path: FileSystemPath) -> Vc<bool> {
Vc::cell(false)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -77,7 +85,7 @@ impl FileSystem for EmbeddedFileSystem { ...@@ -77,7 +85,7 @@ impl FileSystem for EmbeddedFileSystem {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn write_link(&self, _path: FileSystemPath, _target: Vc<LinkContent>) -> Result<Vc<()>> { fn write_link(&self, _path: FileSystemPath, _target: Vc<WriteLinkContent>) -> Result<Vc<()>> {
bail!("Writing is not possible to the embedded filesystem") bail!("Writing is not possible to the embedded filesystem")
} }
......
...@@ -33,7 +33,8 @@ pub mod source_context; ...@@ -33,7 +33,8 @@ pub mod source_context;
pub mod util; pub mod util;
pub(crate) mod virtual_fs; pub(crate) mod virtual_fs;
mod watcher; mod watcher;
mod windows; #[cfg(windows)]
pub mod windows;
use std::{fmt::Debug, fs::FileType, path::PathBuf}; use std::{fmt::Debug, fs::FileType, path::PathBuf};
...@@ -53,7 +54,8 @@ pub(crate) use crate::{ ...@@ -53,7 +54,8 @@ pub(crate) use crate::{
pub use crate::{ pub use crate::{
content::{ content::{
File, FileContent, FileJsonContent, FileLine, FileLinesContent, FileMeta, LinkContent, File, FileContent, FileJsonContent, FileLine, FileLinesContent, FileMeta, LinkContent,
LinkType, Permissions, PersistedFileContent, LinkTarget, Permissions, PersistedFileContent, WriteLinkContent, WriteLinkTarget,
WriteLinkTargetType,
}, },
disk::{DiskFileSystem, canonicalize_to_rcstr, validate_path_length}, disk::{DiskFileSystem, canonicalize_to_rcstr, validate_path_length},
null_fs::NullFileSystem, null_fs::NullFileSystem,
...@@ -61,7 +63,6 @@ pub use crate::{ ...@@ -61,7 +63,6 @@ pub use crate::{
read_glob::ReadGlobResult, read_glob::ReadGlobResult,
virtual_fs::VirtualFileSystem, virtual_fs::VirtualFileSystem,
watcher::{DiskWatcherConfig, DiskWatcherPathMatcher, DiskWatcherRecursiveMode}, watcher::{DiskWatcherConfig, DiskWatcherPathMatcher, DiskWatcherRecursiveMode},
windows::to_verbatim_with_case_folded_disk,
}; };
#[turbo_tasks::value_trait] #[turbo_tasks::value_trait]
...@@ -73,23 +74,20 @@ pub trait FileSystem: ValueToString { ...@@ -73,23 +74,20 @@ pub trait FileSystem: ValueToString {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn read(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<FileContent>; fn read(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<FileContent>;
/// Reads the target of a symbolic link (or of a junction point on Windows). /// Reads the target of a symbolic link (or junction point on Windows). See [`LinkContent`].
///
/// The base of the returned [`LinkContent::Link`] `target` depends on the link's
/// [`LinkType`]: root-relative and normalized for [`LinkType::ABSOLUTE`] links, or the raw
/// link-relative on-disk value otherwise.
///
/// Returns [`LinkContent::Invalid`] if the target points outside of the filesystem root, and
/// [`LinkContent::NotFound`] if `fs_path` doesn't exist or isn't a link.
#[turbo_tasks::function] #[turbo_tasks::function]
fn read_link(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<LinkContent>; fn read_link(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<LinkContent>;
/// Returns whether a symbolic link is a junction point on Windows. Always `false` on all other
/// platforms.
#[turbo_tasks::function]
fn is_junction_point(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<bool>;
#[turbo_tasks::function] #[turbo_tasks::function]
fn raw_read_dir(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<RawDirectoryContent>; fn raw_read_dir(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<RawDirectoryContent>;
#[turbo_tasks::function] #[turbo_tasks::function]
fn write(self: Vc<Self>, fs_path: FileSystemPath, content: Vc<FileContent>) -> Vc<()>; fn write(self: Vc<Self>, fs_path: FileSystemPath, content: Vc<FileContent>) -> Vc<()>;
/// See [`FileSystemPath::write_symbolic_link_dir`]. /// Creates a symbolic link. See [`WriteLinkContent`] and [`FileSystemPath::write_link`].
#[turbo_tasks::function] #[turbo_tasks::function]
fn write_link(self: Vc<Self>, fs_path: FileSystemPath, target: Vc<LinkContent>) -> Vc<()>; fn write_link(self: Vc<Self>, fs_path: FileSystemPath, target: Vc<WriteLinkContent>) -> Vc<()>;
#[turbo_tasks::function] #[turbo_tasks::function]
fn metadata(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<FileMeta>; fn metadata(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<FileMeta>;
} }
......
//! [`NullFileSystem`], a filesystem where every path is empty/not-found. //! [`NullFileSystem`], a filesystem where every path is empty/not-found.
use turbo_rcstr::rcstr;
use turbo_tasks::{ValueToString, Vc}; use turbo_tasks::{ValueToString, Vc};
use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent}; use crate::{
FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
WriteLinkContent,
};
#[derive(ValueToString)] #[derive(ValueToString)]
#[value_to_string("null")] #[value_to_string("null")]
...@@ -18,7 +22,15 @@ impl FileSystem for NullFileSystem { ...@@ -18,7 +22,15 @@ impl FileSystem for NullFileSystem {
#[turbo_tasks::function] #[turbo_tasks::function]
fn read_link(&self, _fs_path: FileSystemPath) -> Vc<LinkContent> { fn read_link(&self, _fs_path: FileSystemPath) -> Vc<LinkContent> {
LinkContent::NotFound.cell() LinkContent::Invalid {
reason: rcstr!("the filesystem does not support symbolic links"),
}
.cell()
}
#[turbo_tasks::function]
fn is_junction_point(&self, _fs_path: FileSystemPath) -> Vc<bool> {
Vc::cell(false)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -30,7 +42,7 @@ impl FileSystem for NullFileSystem { ...@@ -30,7 +42,7 @@ impl FileSystem for NullFileSystem {
fn write(&self, _fs_path: FileSystemPath, _content: Vc<FileContent>) {} fn write(&self, _fs_path: FileSystemPath, _content: Vc<FileContent>) {}
#[turbo_tasks::function] #[turbo_tasks::function]
fn write_link(&self, _fs_path: FileSystemPath, _target: Vc<LinkContent>) {} fn write_link(&self, _fs_path: FileSystemPath, _target: Vc<WriteLinkContent>) {}
#[turbo_tasks::function] #[turbo_tasks::function]
fn metadata(&self, _fs_path: FileSystemPath) -> Vc<FileMeta> { fn metadata(&self, _fs_path: FileSystemPath) -> Vc<FileMeta> {
......
...@@ -6,7 +6,7 @@ use anyhow::{Result, bail}; ...@@ -6,7 +6,7 @@ use anyhow::{Result, bail};
use auto_hash_map::{AutoMap, AutoSet}; use auto_hash_map::{AutoMap, AutoSet};
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use indexmap::IndexSet; use indexmap::IndexSet;
use turbo_rcstr::RcStr; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
Completion, NonLocalValue, ResolvedVc, ValueToString, ValueToStringRef, Vc, trace::TraceRawVcs, Completion, NonLocalValue, ResolvedVc, ValueToString, ValueToStringRef, Vc, trace::TraceRawVcs,
turbobail, turbofmt, turbobail, turbofmt,
...@@ -16,8 +16,8 @@ use turbo_unix_path::{get_parent_path, get_relative_path_to, join_path, normaliz ...@@ -16,8 +16,8 @@ use turbo_unix_path::{get_parent_path, get_relative_path_to, join_path, normaliz
use crate::{ use crate::{
DirectoryContent, DirectoryEntry, FileContent, FileJsonContent, FileMeta, FileSystem, DirectoryContent, DirectoryEntry, FileContent, FileJsonContent, FileMeta, FileSystem,
FileSystemEntryType, LinkContent, LinkType, RawDirectoryContent, RawDirectoryEntry, FileSystemEntryType, LinkContent, RawDirectoryContent, RawDirectoryEntry, ReadGlobResult,
ReadGlobResult, WriteLinkContent,
glob::Glob, glob::Glob,
read_glob::{read_glob, track_glob}, read_glob::{read_glob, track_glob},
}; };
...@@ -391,6 +391,10 @@ impl FileSystemPath { ...@@ -391,6 +391,10 @@ impl FileSystemPath {
self.fs().read_link(self.clone()) self.fs().read_link(self.clone())
} }
pub fn is_junction_point(&self) -> Vc<bool> {
self.fs().is_junction_point(self.clone())
}
pub fn read_json(&self) -> Vc<FileJsonContent> { pub fn read_json(&self) -> Vc<FileJsonContent> {
self.fs().read(self.clone()).parse_json() self.fs().read(self.clone()).parse_json()
} }
...@@ -420,24 +424,20 @@ impl FileSystemPath { ...@@ -420,24 +424,20 @@ impl FileSystemPath {
self.fs().write(self.clone(), content) self.fs().write(self.clone(), content)
} }
/// Creates a symbolic link to a directory on *nix platforms, or a directory junction point on /// Creates a symbolic link on *nix platforms. On Windows, directory links are created as
/// Windows. /// junction points. Links to files on Windows are attempted to be created as symbolic links.
/// ///
/// [Windows supports symbolic links][windows-symlink], but they [can require elevated /// [Windows supports symbolic links][windows-symlink], but they [can require elevated
/// privileges][windows-privileges] if "developer mode" is not enabled, so we can't safely use /// privileges][windows-privileges] if "developer mode" is not enabled, so we can't safely use
/// them. Using junction points [matches the behavior of pnpm][pnpm-windows]. /// them. Using junction points [matches the behavior of pnpm][pnpm-windows].
/// ///
/// This only supports directories because Windows junction points are incompatible with files. /// It is not recommended to create non-directory links, as this is not portable and will likely
/// To ensure compatibility, this will return an error if the target is a file, even on /// fail on Windows.
/// platforms with full symlink support.
///
/// **We intentionally do not provide an API for symlinking a file**, as we cannot support that
/// on all Windows configurations.
/// ///
/// [windows-symlink]: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/ /// [windows-symlink]: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
/// [windows-privileges]: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/security-policy-settings/create-symbolic-links /// [windows-privileges]: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/security-policy-settings/create-symbolic-links
/// [pnpm-windows]: https://pnpm.io/faq#does-it-work-on-windows /// [pnpm-windows]: https://pnpm.io/faq#does-it-work-on-windows
pub fn write_symbolic_link_dir(&self, target: Vc<LinkContent>) -> Vc<()> { pub fn write_link(&self, target: Vc<WriteLinkContent>) -> Vc<()> {
self.fs().write_link(self.clone(), target) self.fs().write_link(self.clone(), target)
} }
...@@ -511,8 +511,12 @@ pub struct RealPathResult { ...@@ -511,8 +511,12 @@ pub struct RealPathResult {
pub enum RealPathResultError { pub enum RealPathResultError {
TooManySymlinks, TooManySymlinks,
CycleDetected, CycleDetected,
Invalid, /// The first symlink that resolution attempted to read no longer exists.
NotFound, NotFound,
/// Resolution failed after finding a symlink, or the symlink was invalid to begin with.
Invalid {
reason: RcStr,
},
} }
impl RealPathResultError { impl RealPathResultError {
...@@ -536,12 +540,14 @@ impl RealPathResultError { ...@@ -536,12 +540,14 @@ impl RealPathResultError {
); );
turbofmt!("Symlink {orig} is in a symlink loop: {symlinks_dbg}").await? turbofmt!("Symlink {orig} is in a symlink loop: {symlinks_dbg}").await?
} }
RealPathResultError::Invalid => { RealPathResultError::Invalid { reason } => {
turbofmt!("Symlink {orig} is invalid, it points out of the filesystem root").await? turbofmt!("Symlink {orig} could not be resolved: {reason}").await?
} }
RealPathResultError::NotFound => { RealPathResultError::NotFound => {
turbofmt!("Symlink {orig} is invalid, it points at a file that doesn't exist") turbofmt!(
.await? "Symlink {orig} could not be read because the symlink itself no longer exists"
)
.await?
} }
}) })
} }
...@@ -605,6 +611,9 @@ async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>> ...@@ -605,6 +611,9 @@ async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>>
let mut symlinks: IndexSet<FileSystemPath> = IndexSet::new(); let mut symlinks: IndexSet<FileSystemPath> = IndexSet::new();
let mut visited: AutoSet<RcStr> = AutoSet::new(); let mut visited: AutoSet<RcStr> = AutoSet::new();
let mut error = RealPathResultError::TooManySymlinks; let mut error = RealPathResultError::TooManySymlinks;
// Whether a previous iteration resolved a symbolic link, so `current_path` is now a link
// target rather than the path we were asked about.
let mut followed_link = false;
// Pick some arbitrary symlink depth limit... similar to the ELOOP logic for realpath(3). // Pick some arbitrary symlink depth limit... similar to the ELOOP logic for realpath(3).
// SYMLOOP_MAX is 40 for Linux: https://unix.stackexchange.com/q/721724 // SYMLOOP_MAX is 40 for Linux: https://unix.stackexchange.com/q/721724
for _i in 0..40 { for _i in 0..40 {
...@@ -630,25 +639,44 @@ async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>> ...@@ -630,25 +639,44 @@ async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>>
.rsplit_once('/') .rsplit_once('/')
.map_or(current_path.path.as_str(), |(_, name)| name); .map_or(current_path.path.as_str(), |(_, name)| name);
symlinks.extend(parent_result.symlinks); symlinks.extend(parent_result.symlinks);
let parent_path = match parent_result.path_result { match parent_result.path_result {
Ok(path) => { Ok(path) => {
if path != parent { if path != parent {
current_path = path.join(basename)?; current_path = path.join(basename)?;
} }
path
} }
Err(parent_error) => { Err(parent_error) => {
error = parent_error; error = match parent_error {
RealPathResultError::NotFound if !symlinks.is_empty() => {
RealPathResultError::Invalid {
reason: rcstr!(
"a symlink encountered while resolving the path no longer exists"
),
}
}
error => error,
};
break; break;
} }
}; }
// use `get_type` before trying `read_link`, as there's a good chance of a cache hit on // use `get_type` before trying `read_link`, as there's a good chance of a cache hit on
// `get_type`, and `read_link` isn't the common codepath. // `get_type`, and `read_link` isn't the common codepath.
if !matches!( let entry_type = *current_path.get_type().await?;
*current_path.get_type().await?, if !matches!(entry_type, FileSystemEntryType::Symlink) {
FileSystemEntryType::Symlink // A link we followed points at something that doesn't exist. `read_link` can't detect
) { // this, as it never looks at the target, so a dangling link reads back as valid.
//
// Only report this for a link we actually followed: resolving a path that simply
// doesn't exist is not an error, it just resolves to itself.
if (followed_link || !symlinks.is_empty())
&& matches!(entry_type, FileSystemEntryType::NotFound)
{
error = RealPathResultError::Invalid {
reason: rcstr!("a symlink target does not exist"),
};
break;
}
return Ok(RealPathResult { return Ok(RealPathResult {
path_result: Ok(current_path), path_result: Ok(current_path),
symlinks: symlinks.into_iter().collect(), // convert set to vec symlinks: symlinks.into_iter().collect(), // convert set to vec
...@@ -656,22 +684,30 @@ async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>> ...@@ -656,22 +684,30 @@ async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>>
.cell()); .cell());
} }
match &*current_path.read_link().await? { let link_content = current_path.read_link().await?;
LinkContent::Link { target, link_type } => { match &*link_content {
symlinks.insert(current_path.clone()); LinkContent::Link { target } => {
current_path = if link_type.contains(LinkType::ABSOLUTE) { let target_path = target.file_system_path().clone();
current_path.root().owned().await? symlinks.insert(current_path);
} else { current_path = target_path;
parent_path followed_link = true;
}
.join(target)?;
} }
LinkContent::NotFound => { LinkContent::NotFound => {
error = RealPathResultError::NotFound; error = if symlinks.is_empty() {
RealPathResultError::NotFound
} else {
RealPathResultError::Invalid {
reason: rcstr!(
"a symlink encountered while resolving the path no longer exists"
),
}
};
break; break;
} }
LinkContent::Invalid => { LinkContent::Invalid { reason } => {
error = RealPathResultError::Invalid; error = RealPathResultError::Invalid {
reason: reason.clone(),
};
break; break;
} }
} }
......
...@@ -5,7 +5,8 @@ use turbo_rcstr::RcStr; ...@@ -5,7 +5,8 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ResolvedVc, TryJoinIterExt, Vc, turbobail}; use turbo_tasks::{Completion, ResolvedVc, TryJoinIterExt, Vc, turbobail};
use crate::{ use crate::{
DirectoryContent, DirectoryEntry, FileSystem, FileSystemPath, LinkContent, LinkType, glob::Glob, DirectoryContent, DirectoryEntry, FileSystem, FileSystemEntryType, FileSystemPath, LinkContent,
glob::Glob,
}; };
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -85,8 +86,11 @@ async fn read_glob_internal( ...@@ -85,8 +86,11 @@ async fn read_glob_internal(
handle_dir(&mut result, entry_path, segment, path).await?; handle_dir(&mut result, entry_path, segment, path).await?;
} }
DirectoryEntry::Symlink(path) => { DirectoryEntry::Symlink(path) => {
if let LinkContent::Link { link_type, .. } = &*path.read_link().await? { // Skip links that leave the filesystem root.
if link_type.contains(LinkType::DIRECTORY) { let link_content = path.read_link().await?;
if let LinkContent::Link { target } = &*link_content {
if matches!(target.target_type().await?, FileSystemEntryType::Directory)
{
// Ensure that there are no infinite link loops, but don't resolve // Ensure that there are no infinite link loops, but don't resolve
resolve_symlink_safely(entry.clone()).await?; resolve_symlink_safely(entry.clone()).await?;
......
...@@ -2,7 +2,10 @@ use anyhow::{Result, bail}; ...@@ -2,7 +2,10 @@ use anyhow::{Result, bail};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ValueToString, Vc}; use turbo_tasks::{ValueToString, Vc};
use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent}; use crate::{
FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
WriteLinkContent,
};
#[derive(ValueToString)] #[derive(ValueToString)]
#[value_to_string(self.name)] #[value_to_string(self.name)]
...@@ -51,6 +54,11 @@ impl FileSystem for VirtualFileSystem { ...@@ -51,6 +54,11 @@ impl FileSystem for VirtualFileSystem {
bail!("Reading is not possible on the virtual file system") bail!("Reading is not possible on the virtual file system")
} }
#[turbo_tasks::function]
fn is_junction_point(&self, _fs_path: FileSystemPath) -> Result<Vc<bool>> {
bail!("Reading is not possible on the virtual file system")
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> { fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> {
bail!("Reading is not possible on the virtual file system") bail!("Reading is not possible on the virtual file system")
...@@ -62,7 +70,11 @@ impl FileSystem for VirtualFileSystem { ...@@ -62,7 +70,11 @@ impl FileSystem for VirtualFileSystem {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn write_link(&self, _fs_path: FileSystemPath, _target: Vc<LinkContent>) -> Result<Vc<()>> { fn write_link(
&self,
_fs_path: FileSystemPath,
_target: Vc<WriteLinkContent>,
) -> Result<Vc<()>> {
bail!("Writing is not possible on the virtual file system") bail!("Writing is not possible on the virtual file system")
} }
......
use std::path::{Path, PathBuf}; use std::{
ffi::OsString,
io, mem,
os::windows::ffi::{OsStrExt, OsStringExt},
path::{Component, Path, PathBuf, Prefix},
ptr::{null, null_mut},
};
use omnipath::WinPathExt;
use windows_sys::Win32::{
Foundation::{CloseHandle, INVALID_HANDLE_VALUE},
Storage::FileSystem::{
CreateFileW, FILE_ATTRIBUTE_TAG_INFO, FILE_FLAG_BACKUP_SEMANTICS,
FILE_FLAG_OPEN_REPARSE_POINT, FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE,
FileAttributeTagInfo, GetFileInformationByHandleEx, OPEN_EXISTING,
},
System::SystemServices::IO_REPARSE_TAG_MOUNT_POINT,
};
pub(crate) fn is_link_junction_point(path: &Path) -> io::Result<bool> {
let path: Vec<u16> = path.as_os_str().encode_wide().chain(Some(0)).collect();
let handle = unsafe {
CreateFileW(
path.as_ptr(),
0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
null(),
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
null_mut(),
)
};
if handle == INVALID_HANDLE_VALUE {
return Err(io::Error::last_os_error());
}
let mut tag_info = FILE_ATTRIBUTE_TAG_INFO {
FileAttributes: 0,
ReparseTag: 0,
};
let result = unsafe {
GetFileInformationByHandleEx(
handle,
FileAttributeTagInfo,
(&mut tag_info as *mut FILE_ATTRIBUTE_TAG_INFO).cast(),
mem::size_of::<FILE_ATTRIBUTE_TAG_INFO>() as u32,
)
};
let error = if result == 0 {
Some(io::Error::last_os_error())
} else {
None
};
unsafe {
CloseHandle(handle);
}
error.map_or(Ok(tag_info.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT), Err)
}
/// Converts `path` into the verbatim, drive-letter-case-folded representation used internally by /// Converts `path` into the verbatim, drive-letter-case-folded representation used internally by
/// [`crate::DiskFileSystem`] on Windows. /// [`crate::DiskFileSystem`] on Windows.
...@@ -8,57 +65,41 @@ use std::path::{Path, PathBuf}; ...@@ -8,57 +65,41 @@ use std::path::{Path, PathBuf};
/// `canonicalize`, does not touch the disk — it resolves neither symlinks nor 8.3 short names. The /// `canonicalize`, does not touch the disk — it resolves neither symlinks nor 8.3 short names. The
/// drive letter is then upper-cased to match the form `GetFinalPathNameByHandle` (and thus /// drive letter is then upper-cased to match the form `GetFinalPathNameByHandle` (and thus
/// `canonicalize`) produces. /// `canonicalize`) produces.
/// pub fn to_verbatim_with_case_folded_disk(path: &Path) -> io::Result<PathBuf> {
/// No-op on non-Windows platforms (returns `path` unchanged). // `to_verbatim` guarantees an absolute, verbatim path from here on, so there's no
pub fn to_verbatim_with_case_folded_disk(path: &Path) -> std::io::Result<PathBuf> { // non-verbatim case to guard against below.
#[cfg(windows)] let path = path.to_verbatim()?;
{
use std::{
ffi::OsString,
os::windows::ffi::{OsStrExt, OsStringExt},
path::{Component, Prefix},
};
use omnipath::WinPathExt;
// `to_verbatim` guarantees an absolute, verbatim path from here on, so there's no // Only `\\?\C:\...` (`VerbatimDisk`) paths carry a drive letter; verbatim UNC
// non-verbatim case to guard against below. // (`\\?\UNC\...`) and other verbatim device paths (`\\?\prefix`) don't, so there's nothing
let path = path.to_verbatim()?; // to case-fold for those.
//
// Only `\\?\C:\...` (`VerbatimDisk`) paths carry a drive letter; verbatim UNC // We can't read the letter from `VerbatimDisk(disk)` because that value is already
// (`\\?\UNC\...`) and other verbatim device paths (`\\?\prefix`) don't, so there's nothing // normalized to uppercase, so it wouldn't tell us whether the underlying path needs
// to case-fold for those. // rewriting.
// let is_verbatim_disk = matches!(
// We can't read the letter from `VerbatimDisk(disk)` because that value is already path.components().next(),
// normalized to uppercase, so it wouldn't tell us whether the underlying path needs Some(Component::Prefix(prefix)) if matches!(prefix.kind(), Prefix::VerbatimDisk(_))
// rewriting. );
let is_verbatim_disk = matches!( if !is_verbatim_disk {
path.components().next(), return Ok(path);
Some(Component::Prefix(prefix)) if matches!(prefix.kind(), Prefix::VerbatimDisk(_)) }
);
if !is_verbatim_disk {
return Ok(path);
}
// The layout is `\\?\C:\...`, so the drive letter is the 5th UTF-16 code unit (index 4)
// and is guaranteed to be a-z or A-Z.
if let Some(disk) = path.as_os_str().encode_wide().nth(4).map(|disk| disk as u8)
&& disk.is_ascii_lowercase()
{
// we must encode/decode because OsString's internal encoding is opaque/unstable
let mut wide: Vec<u16> = path.as_os_str().encode_wide().collect();
wide[4] = u16::from(disk.to_ascii_uppercase());
return Ok(PathBuf::from(OsString::from_wide(&wide)));
}
Ok(path) // The layout is `\\?\C:\...`, so the drive letter is the 5th UTF-16 code unit (index 4)
// and is guaranteed to be a-z or A-Z.
if let Some(disk) = path.as_os_str().encode_wide().nth(4).map(|disk| disk as u8)
&& disk.is_ascii_lowercase()
{
// we must encode/decode because OsString's internal encoding is opaque/unstable
let mut wide: Vec<u16> = path.as_os_str().encode_wide().collect();
wide[4] = u16::from(disk.to_ascii_uppercase());
return Ok(PathBuf::from(OsString::from_wide(&wide)));
} }
#[cfg(not(windows))] Ok(path)
Ok(path.to_path_buf())
} }
#[cfg(all(test, windows))] #[cfg(test)]
mod tests { mod tests {
use std::path::Path; use std::path::Path;
...@@ -87,4 +128,18 @@ mod tests { ...@@ -87,4 +128,18 @@ mod tests {
r"\\?\UNC\server\share\foo" r"\\?\UNC\server\share\foo"
); );
} }
#[test]
fn identifies_junction_points() {
let scratch = tempfile::tempdir().unwrap();
let target = scratch.path().join("target");
let link = scratch.path().join("link");
let file = scratch.path().join("file");
std::fs::create_dir(&target).unwrap();
std::fs::File::create(&file).unwrap();
std::os::windows::fs::junction_point(&target, &link).unwrap();
assert!(is_link_junction_point(&link).unwrap());
assert!(!is_link_junction_point(&file).unwrap());
}
} }
...@@ -20,7 +20,8 @@ use turbo_tasks::{ ...@@ -20,7 +20,8 @@ use turbo_tasks::{
}; };
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
DiskFileSystem, File, FileContent, FileSystem, FileSystemPath, LinkContent, LinkType, DiskFileSystem, File, FileContent, FileSystem, FileSystemPath, WriteLinkContent,
WriteLinkTarget, WriteLinkTargetType,
}; };
// `read_or_write_all_paths_operation` always writes the sentinel values to files/symlinks. We can // `read_or_write_all_paths_operation` always writes the sentinel values to files/symlinks. We can
...@@ -76,12 +77,12 @@ enum SymlinkMode { ...@@ -76,12 +77,12 @@ enum SymlinkMode {
} }
impl SymlinkMode { impl SymlinkMode {
fn to_link_type(self) -> LinkType { fn is_directory(self) -> bool {
match self { match self {
SymlinkMode::File => LinkType::empty(), SymlinkMode::File => false,
SymlinkMode::Directory => LinkType::DIRECTORY, SymlinkMode::Directory => true,
#[cfg(windows)] #[cfg(windows)]
SymlinkMode::Junction => LinkType::DIRECTORY, SymlinkMode::Junction => true,
} }
} }
} }
...@@ -139,8 +140,7 @@ pub async fn run(args: FsWatcher) -> anyhow::Result<()> { ...@@ -139,8 +140,7 @@ pub async fn run(args: FsWatcher) -> anyhow::Result<()> {
}; };
let track_writes = args.track_writes; let track_writes = args.track_writes;
let symlink_mode = args.symlinks; let symlink_mode = args.symlinks;
let symlink_is_directory = let symlink_is_directory = symlink_mode.map(SymlinkMode::is_directory);
symlink_mode.map(|m| m.to_link_type().contains(LinkType::DIRECTORY));
let effects_op = extract_effects_operation(read_or_write_all_paths_operation( let effects_op = extract_effects_operation(read_or_write_all_paths_operation(
invalidations.clone(), invalidations.clone(),
...@@ -348,12 +348,14 @@ async fn write_link( ...@@ -348,12 +348,14 @@ async fn write_link(
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let path_str = path.path.clone(); let path_str = path.path.clone();
invalidations.0.lock().unwrap().insert(path_str); invalidations.0.lock().unwrap().insert(path_str);
let link_type = if is_directory { let link_content = WriteLinkContent {
LinkType::DIRECTORY target: WriteLinkTarget::Relative(target),
} else { target_type: if is_directory {
LinkType::empty() WriteLinkTargetType::DirectoryOrJunctionPoint
} else {
WriteLinkTargetType::FileNonPortable
},
}; };
let link_content = LinkContent::Link { target, link_type };
let _ = path let _ = path
.fs() .fs()
.write_link(path.clone(), link_content.cell()) .write_link(path.clone(), link_content.cell())
......
...@@ -13,7 +13,10 @@ use turbo_tasks::{ ...@@ -13,7 +13,10 @@ use turbo_tasks::{
read_strongly_consistent_and_apply_effects, take_effects, read_strongly_consistent_and_apply_effects, take_effects,
}; };
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, LinkContent, LinkType}; use turbo_tasks_fs::{
DiskFileSystem, FileSystem, FileSystemPath, WriteLinkContent, WriteLinkTarget,
WriteLinkTargetType,
};
#[derive(Args)] #[derive(Args)]
pub struct SymlinkStress { pub struct SymlinkStress {
...@@ -40,6 +43,15 @@ async fn extract_effects_operation(op: OperationVc<()>) -> anyhow::Result<Vc<Eff ...@@ -40,6 +43,15 @@ async fn extract_effects_operation(op: OperationVc<()>) -> anyhow::Result<Vc<Eff
} }
pub async fn run(args: SymlinkStress) -> anyhow::Result<()> { pub async fn run(args: SymlinkStress) -> anyhow::Result<()> {
// Each batch writes `parallelism` distinct symlinks, so there must be enough to go around.
if args.parallelism > args.symlink_count {
anyhow::bail!(
"--parallelism ({}) must not exceed --symlink-count ({}), since a batch cannot write \
the same symlink twice",
args.parallelism,
args.symlink_count,
);
}
std::fs::create_dir(&args.fs_root)?; std::fs::create_dir(&args.fs_root)?;
let fs_root = args.fs_root.canonicalize()?; let fs_root = args.fs_root.canonicalize()?;
let _guard = FsCleanup { let _guard = FsCleanup {
...@@ -58,7 +70,12 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> { ...@@ -58,7 +70,12 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> {
std::fs::create_dir(&symlinks_dir)?; std::fs::create_dir(&symlinks_dir)?;
let tt = turbo_tasks::TurboTasks::new(TurboTasksBackend::new( let tt = turbo_tasks::TurboTasks::new(TurboTasksBackend::new(
BackendOptions::default(), BackendOptions {
// `noop_backing_storage` is read-only, so asking to persist on shutdown (the default)
// just fails with "Cannot perform write operations on a read-only database".
storage_mode: None,
..Default::default()
},
noop_backing_storage(), noop_backing_storage(),
)); ));
...@@ -102,6 +119,8 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> { ...@@ -102,6 +119,8 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> {
); );
let mut rng = rand::rngs::SmallRng::from_rng(&mut rand::rng()); let mut rng = rand::rngs::SmallRng::from_rng(&mut rand::rng());
// Reused across batches; each batch partially shuffles it to sample distinct symlinks.
let mut symlink_indices: Vec<usize> = (0..symlink_count).collect();
let mut total_writes: u64 = 0; let mut total_writes: u64 = 0;
let mut last_progress_writes: u64 = 0; let mut last_progress_writes: u64 = 0;
let start_time = Instant::now(); let start_time = Instant::now();
...@@ -113,13 +132,18 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> { ...@@ -113,13 +132,18 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> {
break; break;
} }
// Generate random symlink updates for this batch // Pick `parallelism` *distinct* symlinks for this batch, via a partial Fisher-Yates
let updates: Vec<(usize, usize)> = (0..parallelism) // shuffle. They must be distinct because writing two different targets to one path
.map(|_| { // within a single operation is a conflicting effect: a usage error, not something to
let symlink_idx = rng.random_range(0..symlink_count); // stress test. Sampling without replacement (rather than deduplicating) keeps the
let target_idx = rng.random_range(0..target_count); // batch size exactly `parallelism`, so the reported concurrency is honest.
(symlink_idx, target_idx) for i in 0..parallelism {
}) let j = rng.random_range(i..symlink_count);
symlink_indices.swap(i, j);
}
let updates: Vec<(usize, usize)> = symlink_indices[..parallelism]
.iter()
.map(|&symlink_idx| (symlink_idx, rng.random_range(0..target_count)))
.collect(); .collect();
// Execute writes in parallel via turbo-tasks // Execute writes in parallel via turbo-tasks
...@@ -169,17 +193,17 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> { ...@@ -169,17 +193,17 @@ pub async fn run(args: SymlinkStress) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation, root)]
fn disk_file_system_operation(fs_root: RcStr) -> Vc<DiskFileSystem> { fn disk_file_system_operation(fs_root: RcStr) -> Vc<DiskFileSystem> {
DiskFileSystem::new(rcstr!("project"), Vc::cell(fs_root)) DiskFileSystem::new(rcstr!("project"), Vc::cell(fs_root))
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation, root)]
fn disk_file_system_root_operation(fs: ResolvedVc<DiskFileSystem>) -> Vc<FileSystemPath> { fn disk_file_system_root_operation(fs: ResolvedVc<DiskFileSystem>) -> Vc<FileSystemPath> {
fs.root() fs.root()
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation, root)]
async fn create_initial_symlinks_operation( async fn create_initial_symlinks_operation(
symlinks_dir: FileSystemPath, symlinks_dir: FileSystemPath,
count: usize, count: usize,
...@@ -192,7 +216,7 @@ async fn create_initial_symlinks_operation( ...@@ -192,7 +216,7 @@ async fn create_initial_symlinks_operation(
Ok(()) Ok(())
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation, root)]
async fn write_symlinks_batch_operation( async fn write_symlinks_batch_operation(
symlinks_dir: FileSystemPath, symlinks_dir: FileSystemPath,
updates: Vec<(usize, usize)>, updates: Vec<(usize, usize)>,
...@@ -215,9 +239,9 @@ async fn write_symlink( ...@@ -215,9 +239,9 @@ async fn write_symlink(
target: RcStr, target: RcStr,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let symlink_path = symlinks_dir.join(&symlink_idx.to_string())?; let symlink_path = symlinks_dir.join(&symlink_idx.to_string())?;
let link_content = LinkContent::Link { let link_content = WriteLinkContent {
target, target: WriteLinkTarget::Relative(target),
link_type: LinkType::DIRECTORY, target_type: WriteLinkTargetType::DirectoryOrJunctionPoint,
}; };
symlink_path symlink_path
.fs() .fs()
......
...@@ -10,28 +10,27 @@ use crate::expand::{generate_exhaustive_destructuring, match_expansion}; ...@@ -10,28 +10,27 @@ use crate::expand::{generate_exhaustive_destructuring, match_expansion};
/// ///
/// This requires that every contained value also implement `DeterministicHash`. /// This requires that every contained value also implement `DeterministicHash`.
pub fn derive_deterministic_hash(input: TokenStream) -> TokenStream { pub fn derive_deterministic_hash(input: TokenStream) -> TokenStream {
let derive_input = parse_macro_input!(input as DeriveInput); let DeriveInput {
let ident = &derive_input.ident;
let match_hash = match_expansion(
ident, ident,
&derive_input.data, generics,
&hash_named, data,
&hash_unnamed, ..
&hash_unit, } = parse_macro_input!(input as DeriveInput);
);
let discriminant = match derive_input.data { let match_hash = match_expansion(&ident, &data, &hash_named, &hash_unnamed, &hash_unit);
let discriminant = match data {
Data::Enum(_) => { Data::Enum(_) => {
quote! { quote! {
turbo_tasks_hash::DeterministicHash::deterministic_hash(&std::mem::discriminant(self), __state__); ::turbo_tasks_hash::DeterministicHash::deterministic_hash(&std::mem::discriminant(self), __state__);
} }
} }
_ => quote! {}, _ => quote! {},
}; };
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl turbo_tasks_hash::DeterministicHash for #ident { impl #impl_generics ::turbo_tasks_hash::DeterministicHash for #ident #ty_generics #where_clause {
fn deterministic_hash<H: turbo_tasks_hash::DeterministicHasher>(&self, __state__: &mut H) { fn deterministic_hash<H: turbo_tasks_hash::DeterministicHasher>(&self, __state__: &mut H) {
#discriminant #discriminant
#match_hash #match_hash
......
...@@ -6,11 +6,11 @@ use std::borrow::Cow; ...@@ -6,11 +6,11 @@ use std::borrow::Cow;
/// directory separators with forward slashes on Windows. /// directory separators with forward slashes on Windows.
#[inline] #[inline]
pub fn sys_to_unix(path: &str) -> Cow<'_, str> { pub fn sys_to_unix(path: &str) -> Cow<'_, str> {
#[cfg(not(target_family = "windows"))] #[cfg(not(windows))]
{ {
Cow::from(path) Cow::from(path)
} }
#[cfg(target_family = "windows")] #[cfg(windows)]
{ {
Cow::Owned(path.replace(std::path::MAIN_SEPARATOR_STR, "/")) Cow::Owned(path.replace(std::path::MAIN_SEPARATOR_STR, "/"))
} }
...@@ -20,11 +20,11 @@ pub fn sys_to_unix(path: &str) -> Cow<'_, str> { ...@@ -20,11 +20,11 @@ pub fn sys_to_unix(path: &str) -> Cow<'_, str> {
/// slash directory separators with backslashes on Windows. /// slash directory separators with backslashes on Windows.
#[inline] #[inline]
pub fn unix_to_sys(path: &str) -> Cow<'_, str> { pub fn unix_to_sys(path: &str) -> Cow<'_, str> {
#[cfg(not(target_family = "windows"))] #[cfg(not(windows))]
{ {
Cow::from(path) Cow::from(path)
} }
#[cfg(target_family = "windows")] #[cfg(windows)]
{ {
Cow::Owned(path.replace('/', std::path::MAIN_SEPARATOR_STR)) Cow::Owned(path.replace('/', std::path::MAIN_SEPARATOR_STR))
} }
...@@ -36,10 +36,8 @@ pub fn unix_to_sys(path: &str) -> Cow<'_, str> { ...@@ -36,10 +36,8 @@ pub fn unix_to_sys(path: &str) -> Cow<'_, str> {
/// see also [normalize_path] for normalization. /// see also [normalize_path] for normalization.
/// Returns `None` if the joined path would leave the filesystem root. /// Returns `None` if the joined path would leave the filesystem root.
pub fn join_path(fs_path: &str, join: &str) -> Option<String> { pub fn join_path(fs_path: &str, join: &str) -> Option<String> {
// Paths that we join are written as source code (eg, `join_path(fs_path, "foo/bar.js")`) and
// it's expected that they will never contain a backslash.
debug_assert!( debug_assert!(
!join.contains('\\'), !cfg!(windows) || !join.contains('\\'),
"joined path {join} must not contain a Windows directory '\\', it must be normalized to \ "joined path {join} must not contain a Windows directory '\\', it must be normalized to \
Unix '/'" Unix '/'"
); );
......
...@@ -2,7 +2,7 @@ use anyhow::Result; ...@@ -2,7 +2,7 @@ use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileContent, FileJsonContent, FileLinesContent, FileSystemPath, LinkContent, LinkType, FileContent, FileJsonContent, FileLinesContent, FileSystemPath, WriteLinkContent,
}; };
use turbo_tasks_hash::{HashAlgorithm, deterministic_hash}; use turbo_tasks_hash::{HashAlgorithm, deterministic_hash};
...@@ -52,10 +52,8 @@ pub trait Asset { ...@@ -52,10 +52,8 @@ pub trait Asset {
#[derive(Clone)] #[derive(Clone)]
pub enum AssetContent { pub enum AssetContent {
File(ResolvedVc<FileContent>), File(ResolvedVc<FileContent>),
// for the relative link, the target is raw value read from the link /// A symbolic link. See [`WriteLinkContent`] for how it is written.
// for the absolute link, the target is stripped of the root path while reading Redirect(WriteLinkContent),
// See [LinkContent::Link] for more details.
Redirect { target: RcStr, link_type: LinkType },
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -69,7 +67,7 @@ impl AssetContent { ...@@ -69,7 +67,7 @@ impl AssetContent {
pub fn parse_json(&self) -> Vc<FileJsonContent> { pub fn parse_json(&self) -> Vc<FileJsonContent> {
match self { match self {
AssetContent::File(content) => content.parse_json(), AssetContent::File(content) => content.parse_json(),
AssetContent::Redirect { .. } => { AssetContent::Redirect(..) => {
FileJsonContent::unparsable(rcstr!("a redirect can't be parsed as json")).cell() FileJsonContent::unparsable(rcstr!("a redirect can't be parsed as json")).cell()
} }
} }
...@@ -79,7 +77,7 @@ impl AssetContent { ...@@ -79,7 +77,7 @@ impl AssetContent {
pub fn file_content(&self) -> Vc<FileContent> { pub fn file_content(&self) -> Vc<FileContent> {
match self { match self {
AssetContent::File(content) => **content, AssetContent::File(content) => **content,
AssetContent::Redirect { .. } => FileContent::NotFound.cell(), AssetContent::Redirect(..) => FileContent::NotFound.cell(),
} }
} }
...@@ -87,7 +85,7 @@ impl AssetContent { ...@@ -87,7 +85,7 @@ impl AssetContent {
pub fn lines(&self) -> Vc<FileLinesContent> { pub fn lines(&self) -> Vc<FileLinesContent> {
match self { match self {
AssetContent::File(content) => content.lines(), AssetContent::File(content) => content.lines(),
AssetContent::Redirect { .. } => FileLinesContent::Unparsable.cell(), AssetContent::Redirect(..) => FileLinesContent::Unparsable.cell(),
} }
} }
...@@ -95,7 +93,7 @@ impl AssetContent { ...@@ -95,7 +93,7 @@ impl AssetContent {
pub fn len(&self) -> Vc<Option<u64>> { pub fn len(&self) -> Vc<Option<u64>> {
match self { match self {
AssetContent::File(content) => content.len(), AssetContent::File(content) => content.len(),
AssetContent::Redirect { .. } => Vc::cell(None), AssetContent::Redirect(..) => Vc::cell(None),
} }
} }
...@@ -103,7 +101,7 @@ impl AssetContent { ...@@ -103,7 +101,7 @@ impl AssetContent {
pub fn parse_json_with_comments(&self) -> Vc<FileJsonContent> { pub fn parse_json_with_comments(&self) -> Vc<FileJsonContent> {
match self { match self {
AssetContent::File(content) => content.parse_json_with_comments(), AssetContent::File(content) => content.parse_json_with_comments(),
AssetContent::Redirect { .. } => { AssetContent::Redirect(..) => {
FileJsonContent::unparsable(rcstr!("a redirect can't be parsed as json")).cell() FileJsonContent::unparsable(rcstr!("a redirect can't be parsed as json")).cell()
} }
} }
...@@ -115,16 +113,10 @@ impl AssetContent { ...@@ -115,16 +113,10 @@ impl AssetContent {
AssetContent::File(file) => { AssetContent::File(file) => {
path.write(**file).as_side_effect().await?; path.write(**file).as_side_effect().await?;
} }
AssetContent::Redirect { target, link_type } => { AssetContent::Redirect(content) => {
path.write_symbolic_link_dir( path.write_link(content.clone().cell())
LinkContent::Link { .as_side_effect()
target: target.clone(), .await?;
link_type: *link_type,
}
.cell(),
)
.as_side_effect()
.await?;
} }
} }
Ok(()) Ok(())
...@@ -134,9 +126,9 @@ impl AssetContent { ...@@ -134,9 +126,9 @@ impl AssetContent {
pub async fn hash(&self, salt: Vc<RcStr>, algorithm: HashAlgorithm) -> Result<Vc<RcStr>> { pub async fn hash(&self, salt: Vc<RcStr>, algorithm: HashAlgorithm) -> Result<Vc<RcStr>> {
Ok(match self { Ok(match self {
AssetContent::File(content) => content.hash(salt, algorithm), AssetContent::File(content) => content.hash(salt, algorithm),
AssetContent::Redirect { target, link_type } => Vc::cell(RcStr::from( AssetContent::Redirect(content) => Vc::cell(RcStr::from(
// no_hash_salt // no_hash_salt
deterministic_hash(&salt.await?, (target, link_type), algorithm), deterministic_hash(&salt.await?, content, algorithm),
)), )),
}) })
} }
...@@ -154,7 +146,7 @@ impl AssetContent { ...@@ -154,7 +146,7 @@ impl AssetContent {
) -> Result<Vc<Option<RcStr>>> { ) -> Result<Vc<Option<RcStr>>> {
match self { match self {
AssetContent::File(content) => Ok(content.content_hash(salt, algorithm)), AssetContent::File(content) => Ok(content.content_hash(salt, algorithm)),
AssetContent::Redirect { .. } => Ok(Vc::cell(None)), AssetContent::Redirect(..) => Ok(Vc::cell(None)),
} }
} }
} }
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::Vc; use turbo_tasks::Vc;
use turbo_tasks_fs::{FileContent, FileSystemEntryType, FileSystemPath, LinkContent}; use turbo_tasks_fs::{
FileContent, FileSystemEntryType, FileSystemPath, LinkContent, LinkTarget, WriteLinkContent,
WriteLinkTarget, WriteLinkTargetType,
};
use crate::{ use crate::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -66,11 +69,31 @@ impl Asset for FileSource { ...@@ -66,11 +69,31 @@ impl Asset for FileSource {
let file_type = &*self.path.get_type().await?; let file_type = &*self.path.get_type().await?;
match file_type { match file_type {
FileSystemEntryType::Symlink => match &*self.path.read_link().await? { FileSystemEntryType::Symlink => match &*self.path.read_link().await? {
LinkContent::Link { target, link_type } => Ok(AssetContent::Redirect { LinkContent::Link { target } => {
target: target.clone(), let write_target = match target {
link_type: *link_type, LinkTarget::Absolute { resolved } => {
WriteLinkTarget::Absolute(resolved.path.clone())
}
LinkTarget::Relative { raw, .. } => WriteLinkTarget::Relative(raw.clone()),
};
let target_fs_path = target.file_system_path();
let write_target_type = match *target_fs_path.get_type().await? {
FileSystemEntryType::Directory => {
WriteLinkTargetType::DirectoryOrJunctionPoint
}
FileSystemEntryType::Symlink
if *target_fs_path.is_junction_point().await? =>
{
WriteLinkTargetType::DirectoryOrJunctionPoint
}
_ => WriteLinkTargetType::FileNonPortable,
};
Ok(AssetContent::Redirect(WriteLinkContent {
target: write_target,
target_type: write_target_type,
})
.cell())
} }
.cell()),
_ => bail!("Invalid symlink"), _ => bail!("Invalid symlink"),
}, },
FileSystemEntryType::File => { FileSystemEntryType::File => {
......
...@@ -54,9 +54,7 @@ pub async fn content_to_details(content: Vc<AssetContent>) -> Result<Vc<RcStr>> ...@@ -54,9 +54,7 @@ pub async fn content_to_details(content: Vc<AssetContent>) -> Result<Vc<RcStr>>
} }
FileContent::NotFound => Vc::cell(rcstr!("not found")), FileContent::NotFound => Vc::cell(rcstr!("not found")),
}, },
AssetContent::Redirect { target, link_type } => { AssetContent::Redirect(content) => Vc::cell(format!("redirect to {content:?}").into()),
Vc::cell(format!("redirect to {target} with type {link_type:?}").into())
}
}) })
} }
......
...@@ -14,7 +14,7 @@ use turbo_tasks::{ ...@@ -14,7 +14,7 @@ use turbo_tasks::{
NonLocalValue, TaskInput, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, TaskInput, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
}; };
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileSystemPath, LinkContent, LinkType, RawDirectoryContent, RawDirectoryEntry, FileSystemEntryType, FileSystemPath, LinkContent, RawDirectoryContent, RawDirectoryEntry,
}; };
use turbo_unix_path::normalize_path; use turbo_unix_path::normalize_path;
...@@ -1606,12 +1606,12 @@ pub async fn read_matches( ...@@ -1606,12 +1606,12 @@ pub async fn read_matches(
)), )),
RawDirectoryEntry::Symlink => { RawDirectoryEntry::Symlink => {
let fs_path = parent_fs_path.join(last_segment)?; let fs_path = parent_fs_path.join(last_segment)?;
let LinkContent::Link { link_type, .. } = &*fs_path.read_link().await? let LinkContent::Link { target } = &*fs_path.read_link().await? else {
else {
continue; continue;
}; };
let path = concat(&prefix, str).into(); let path = concat(&prefix, str).into();
if link_type.contains(LinkType::DIRECTORY) { if matches!(target.target_type().await?, FileSystemEntryType::Directory)
{
results.push((index, PatternMatch::Directory(path, fs_path))); results.push((index, PatternMatch::Directory(path, fs_path)));
} else { } else {
results.push((index, PatternMatch::File(path, fs_path))) results.push((index, PatternMatch::File(path, fs_path)))
...@@ -1795,10 +1795,13 @@ pub async fn read_matches( ...@@ -1795,10 +1795,13 @@ pub async fn read_matches(
} }
if let Some(pos) = pat.match_position(&prefix) { if let Some(pos) = pat.match_position(&prefix) {
let fs_path = lookup_dir.join(key)?; let fs_path = lookup_dir.join(key)?;
if let LinkContent::Link { link_type, .. } = if let LinkContent::Link { target } =
&*fs_path.read_link().await? &*fs_path.read_link().await?
{ {
if link_type.contains(LinkType::DIRECTORY) { if matches!(
target.target_type().await?,
FileSystemEntryType::Directory
) {
results.push(( results.push((
pos, pos,
PatternMatch::Directory( PatternMatch::Directory(
...@@ -1817,9 +1820,12 @@ pub async fn read_matches( ...@@ -1817,9 +1820,12 @@ pub async fn read_matches(
prefix.push('/'); prefix.push('/');
if let Some(pos) = pat.match_position(&prefix) { if let Some(pos) = pat.match_position(&prefix) {
let fs_path = lookup_dir.join(key)?; let fs_path = lookup_dir.join(key)?;
if let LinkContent::Link { link_type, .. } = if let LinkContent::Link { target } =
&*fs_path.read_link().await? &*fs_path.read_link().await?
&& link_type.contains(LinkType::DIRECTORY) && matches!(
target.target_type().await?,
FileSystemEntryType::Directory
)
{ {
results.push(( results.push((
pos, pos,
...@@ -1829,9 +1835,12 @@ pub async fn read_matches( ...@@ -1829,9 +1835,12 @@ pub async fn read_matches(
} }
if let Some(pos) = pat.could_match_position(&prefix) { if let Some(pos) = pat.could_match_position(&prefix) {
let fs_path = lookup_dir.join(key)?; let fs_path = lookup_dir.join(key)?;
if let LinkContent::Link { link_type, .. } = if let LinkContent::Link { target } =
&*fs_path.read_link().await? &*fs_path.read_link().await?
&& link_type.contains(LinkType::DIRECTORY) && matches!(
target.target_type().await?,
FileSystemEntryType::Directory
)
{ {
results.push(( results.push((
pos, pos,
......
...@@ -2,6 +2,7 @@ use anyhow::{Result, bail}; ...@@ -2,6 +2,7 @@ use anyhow::{Result, bail};
use turbo_tasks::{ValueToString, Vc}; use turbo_tasks::{ValueToString, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
WriteLinkContent,
}; };
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -29,6 +30,11 @@ impl FileSystem for ServerFileSystem { ...@@ -29,6 +30,11 @@ impl FileSystem for ServerFileSystem {
bail!("Reading is not possible from the marker filesystem for the server") bail!("Reading is not possible from the marker filesystem for the server")
} }
#[turbo_tasks::function]
fn is_junction_point(&self, _fs_path: FileSystemPath) -> Result<Vc<bool>> {
bail!("Reading is not possible from the marker filesystem for the server")
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> { fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> {
bail!("Reading is not possible from the marker filesystem for the server") bail!("Reading is not possible from the marker filesystem for the server")
...@@ -40,7 +46,11 @@ impl FileSystem for ServerFileSystem { ...@@ -40,7 +46,11 @@ impl FileSystem for ServerFileSystem {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn write_link(&self, _fs_path: FileSystemPath, _target: Vc<LinkContent>) -> Result<Vc<()>> { fn write_link(
&self,
_fs_path: FileSystemPath,
_target: Vc<WriteLinkContent>,
) -> Result<Vc<()>> {
bail!("Writing is not possible to the marker filesystem for the server") bail!("Writing is not possible to the marker filesystem for the server")
} }
......
...@@ -234,7 +234,7 @@ impl FileHashVersion { ...@@ -234,7 +234,7 @@ impl FileHashVersion {
.context("file not found")?; .context("file not found")?;
Ok(Self::cell(FileHashVersion { hash })) Ok(Self::cell(FileHashVersion { hash }))
} }
AssetContent::Redirect { .. } => bail!("not a file"), AssetContent::Redirect(..) => bail!("not a file"),
} }
} }
} }
......
...@@ -378,7 +378,7 @@ pub async fn parse_css( ...@@ -378,7 +378,7 @@ pub async fn parse_css(
let content = source.content(); let content = source.content();
let ident_str = &*source.ident().to_string().await?; let ident_str = &*source.ident().to_string().await?;
Ok(match &*content.await? { Ok(match &*content.await? {
AssetContent::Redirect { .. } => ParseCssResult::Unparsable.cell(), AssetContent::Redirect(..) => ParseCssResult::Unparsable.cell(),
AssetContent::File(file_content) => match &*file_content.await? { AssetContent::File(file_content) => match &*file_content.await? {
FileContent::NotFound => ParseCssResult::NotFound.cell(), FileContent::NotFound => ParseCssResult::NotFound.cell(),
FileContent::Content(file) => match file.content().to_str() { FileContent::Content(file) => match file.content().to_str() {
......
...@@ -372,7 +372,7 @@ async fn parse_internal( ...@@ -372,7 +372,7 @@ async fn parse_internal(
} }
} }
}, },
AssetContent::Redirect { .. } => ParseResult::Unparsable { messages: None }.cell(), AssetContent::Redirect(..) => ParseResult::Unparsable { messages: None }.cell(),
}) })
} }
......
...@@ -4,7 +4,10 @@ use anyhow::{Context, Result}; ...@@ -4,7 +4,10 @@ use anyhow::{Context, Result};
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToStringRef, Vc, trace::TraceRawVcs}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToStringRef, Vc, trace::TraceRawVcs};
use turbo_tasks_fs::{FileSystem, FileSystemPath, LinkType, VirtualFileSystem, rope::RopeBuilder}; use turbo_tasks_fs::{
FileSystem, FileSystemPath, VirtualFileSystem, WriteLinkContent, WriteLinkTarget,
WriteLinkTargetType, rope::RopeBuilder,
};
use turbo_tasks_hash::{encode_hex, hash_xxh3_hash64}; use turbo_tasks_hash::{encode_hex, hash_xxh3_hash64};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -508,10 +511,10 @@ impl Asset for ExternalsSymlinkAsset { ...@@ -508,10 +511,10 @@ impl Asset for ExternalsSymlinkAsset {
) )
.into(); .into();
Ok(AssetContent::Redirect { Ok(AssetContent::Redirect(WriteLinkContent {
target, target: WriteLinkTarget::Relative(target),
link_type: LinkType::DIRECTORY, target_type: WriteLinkTargetType::DirectoryOrJunctionPoint,
} })
.cell()) .cell())
} }
} }
...@@ -169,9 +169,7 @@ async fn get_contents(file: Vc<AssetContent>) -> Result<Option<String>> { ...@@ -169,9 +169,7 @@ async fn get_contents(file: Vc<AssetContent>) -> Result<Option<String>> {
} }
} }
}, },
AssetContent::Redirect { target, link_type } => Some(format!( AssetContent::Redirect(content) => Some(format!("Redirect {content:?}")),
"Redirect {{ target: {target}, link_type: {link_type:?} }}"
)),
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment