Unverified Commit 5c38caab authored by xusd320's avatar xusd320 Committed by GitHub

refactor(turbo-tasks-fs): change FS to_sys_path to be synchronous (#82341)

parent d6337894
...@@ -541,7 +541,7 @@ async fn benchmark_file_io( ...@@ -541,7 +541,7 @@ async fn benchmark_file_io(
))? ))?
.await?; .await?;
let directory = fs.to_sys_path(directory).await?; let directory = fs.to_sys_path(directory)?;
let temp_path = directory.join(format!( let temp_path = directory.join(format!(
"tmp_file_io_benchmark_{:x}", "tmp_file_io_benchmark_{:x}",
rand::random::<u128>() rand::random::<u128>()
......
...@@ -474,7 +474,7 @@ impl DiskFileSystem { ...@@ -474,7 +474,7 @@ impl DiskFileSystem {
self.inner.watcher.stop_watching(); self.inner.watcher.stop_watching();
} }
pub async fn to_sys_path(&self, fs_path: FileSystemPath) -> Result<PathBuf> { pub fn to_sys_path(&self, fs_path: FileSystemPath) -> Result<PathBuf> {
// just in case there's a windows unc path prefix we remove it with `dunce` // just in case there's a windows unc path prefix we remove it with `dunce`
let path = self.inner.root_path(); let path = self.inner.root_path();
Ok(if fs_path.path.is_empty() { Ok(if fs_path.path.is_empty() {
...@@ -545,7 +545,7 @@ impl FileSystem for DiskFileSystem { ...@@ -545,7 +545,7 @@ impl FileSystem for DiskFileSystem {
#[turbo_tasks::function(fs)] #[turbo_tasks::function(fs)]
async fn read(&self, fs_path: FileSystemPath) -> Result<Vc<FileContent>> { async fn read(&self, fs_path: FileSystemPath) -> Result<Vc<FileContent>> {
mark_session_dependent(); mark_session_dependent();
let full_path = self.to_sys_path(fs_path).await?; let full_path = self.to_sys_path(fs_path)?;
self.inner.register_read_invalidator(&full_path)?; self.inner.register_read_invalidator(&full_path)?;
let _lock = self.inner.lock_path(&full_path).await; let _lock = self.inner.lock_path(&full_path).await;
...@@ -571,7 +571,7 @@ impl FileSystem for DiskFileSystem { ...@@ -571,7 +571,7 @@ impl FileSystem for DiskFileSystem {
#[turbo_tasks::function(fs)] #[turbo_tasks::function(fs)]
async fn raw_read_dir(&self, fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> { async fn raw_read_dir(&self, fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> {
mark_session_dependent(); mark_session_dependent();
let full_path = self.to_sys_path(fs_path).await?; let full_path = self.to_sys_path(fs_path)?;
self.inner.register_dir_invalidator(&full_path)?; self.inner.register_dir_invalidator(&full_path)?;
// we use the sync std function here as it's a lot faster (600%) in // we use the sync std function here as it's a lot faster (600%) in
...@@ -626,7 +626,7 @@ impl FileSystem for DiskFileSystem { ...@@ -626,7 +626,7 @@ impl FileSystem for DiskFileSystem {
#[turbo_tasks::function(fs)] #[turbo_tasks::function(fs)]
async fn read_link(&self, fs_path: FileSystemPath) -> Result<Vc<LinkContent>> { async fn read_link(&self, fs_path: FileSystemPath) -> Result<Vc<LinkContent>> {
mark_session_dependent(); mark_session_dependent();
let full_path = self.to_sys_path(fs_path.clone()).await?; let full_path = self.to_sys_path(fs_path.clone())?;
self.inner.register_read_invalidator(&full_path)?; self.inner.register_read_invalidator(&full_path)?;
let _lock = self.inner.lock_path(&full_path).await; let _lock = self.inner.lock_path(&full_path).await;
...@@ -716,7 +716,7 @@ impl FileSystem for DiskFileSystem { ...@@ -716,7 +716,7 @@ impl FileSystem for DiskFileSystem {
// `write` purely declares a side effect and does not need to be reexecuted in the next // `write` purely declares a side effect and does not need to be reexecuted in the next
// session. All side effects are reexecuted in general. // session. All side effects are reexecuted in general.
let full_path = self.to_sys_path(fs_path).await?; let full_path = self.to_sys_path(fs_path)?;
let content = content.await?; let content = content.await?;
let inner = self.inner.clone(); let inner = self.inner.clone();
let invalidator = turbo_tasks::get_invalidator(); let invalidator = turbo_tasks::get_invalidator();
...@@ -851,7 +851,7 @@ impl FileSystem for DiskFileSystem { ...@@ -851,7 +851,7 @@ impl FileSystem for DiskFileSystem {
// `write_link` purely declares a side effect and does not need to be reexecuted in the next // `write_link` purely declares a side effect and does not need to be reexecuted in the next
// session. All side effects are reexecuted in general. // session. All side effects are reexecuted in general.
let full_path = self.to_sys_path(fs_path).await?; let full_path = self.to_sys_path(fs_path)?;
let content = target.await?; let content = target.await?;
let inner = self.inner.clone(); let inner = self.inner.clone();
let invalidator = turbo_tasks::get_invalidator(); let invalidator = turbo_tasks::get_invalidator();
...@@ -975,7 +975,7 @@ impl FileSystem for DiskFileSystem { ...@@ -975,7 +975,7 @@ impl FileSystem for DiskFileSystem {
#[turbo_tasks::function(fs)] #[turbo_tasks::function(fs)]
async fn metadata(&self, fs_path: FileSystemPath) -> Result<Vc<FileMeta>> { async fn metadata(&self, fs_path: FileSystemPath) -> Result<Vc<FileMeta>> {
mark_session_dependent(); mark_session_dependent();
let full_path = self.to_sys_path(fs_path).await?; let full_path = self.to_sys_path(fs_path)?;
self.inner.register_read_invalidator(&full_path)?; self.inner.register_read_invalidator(&full_path)?;
let _lock = self.inner.lock_path(&full_path).await; let _lock = self.inner.lock_path(&full_path).await;
...@@ -2308,7 +2308,7 @@ pub async fn to_sys_path(mut path: FileSystemPath) -> Result<Option<PathBuf>> { ...@@ -2308,7 +2308,7 @@ pub async fn to_sys_path(mut path: FileSystemPath) -> Result<Option<PathBuf>> {
} }
if let Some(fs) = Vc::try_resolve_downcast_type::<DiskFileSystem>(path.fs()).await? { if let Some(fs) = Vc::try_resolve_downcast_type::<DiskFileSystem>(path.fs()).await? {
let sys_path = fs.await?.to_sys_path(path).await?; let sys_path = fs.await?.to_sys_path(path)?;
return Ok(Some(sys_path)); return Ok(Some(sys_path));
} }
......
...@@ -152,8 +152,7 @@ pub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<S ...@@ -152,8 +152,7 @@ pub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<S
.to_sys_path(match path { .to_sys_path(match path {
Some(path) => root.join(path)?, Some(path) => root.join(path)?,
None => root, None => root,
}) })?
.await?
.to_string_lossy() .to_string_lossy()
) )
.split('/') .split('/')
...@@ -171,12 +170,10 @@ pub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<S ...@@ -171,12 +170,10 @@ pub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<S
.context("Expected root to have a DiskFileSystem")? .context("Expected root to have a DiskFileSystem")?
.await?; .await?;
let sys_path = root_fs let sys_path = root_fs.to_sys_path(match path {
.to_sys_path(match path { Some(path) => root.join(path.into())?,
Some(path) => root.join(path.into())?, None => root,
None => root, })?;
})
.await?;
let raw_path = sys_path.to_string_lossy().to_string(); let raw_path = sys_path.to_string_lossy().to_string();
let normalized_path = raw_path.replace('\\', "/"); let normalized_path = raw_path.replace('\\', "/");
......
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