Skip to content

Commit 5c38caa

Browse files
authored
refactor(turbo-tasks-fs): change FS to_sys_path to be synchronous (#82341)
1 parent d633789 commit 5c38caa

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

crates/napi/src/next_api/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ async fn benchmark_file_io(
541541
))?
542542
.await?;
543543

544-
let directory = fs.to_sys_path(directory).await?;
544+
let directory = fs.to_sys_path(directory)?;
545545
let temp_path = directory.join(format!(
546546
"tmp_file_io_benchmark_{:x}",
547547
rand::random::<u128>()

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl DiskFileSystem {
474474
self.inner.watcher.stop_watching();
475475
}
476476

477-
pub async fn to_sys_path(&self, fs_path: FileSystemPath) -> Result<PathBuf> {
477+
pub fn to_sys_path(&self, fs_path: FileSystemPath) -> Result<PathBuf> {
478478
// just in case there's a windows unc path prefix we remove it with `dunce`
479479
let path = self.inner.root_path();
480480
Ok(if fs_path.path.is_empty() {
@@ -545,7 +545,7 @@ impl FileSystem for DiskFileSystem {
545545
#[turbo_tasks::function(fs)]
546546
async fn read(&self, fs_path: FileSystemPath) -> Result<Vc<FileContent>> {
547547
mark_session_dependent();
548-
let full_path = self.to_sys_path(fs_path).await?;
548+
let full_path = self.to_sys_path(fs_path)?;
549549
self.inner.register_read_invalidator(&full_path)?;
550550

551551
let _lock = self.inner.lock_path(&full_path).await;
@@ -571,7 +571,7 @@ impl FileSystem for DiskFileSystem {
571571
#[turbo_tasks::function(fs)]
572572
async fn raw_read_dir(&self, fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> {
573573
mark_session_dependent();
574-
let full_path = self.to_sys_path(fs_path).await?;
574+
let full_path = self.to_sys_path(fs_path)?;
575575
self.inner.register_dir_invalidator(&full_path)?;
576576

577577
// we use the sync std function here as it's a lot faster (600%) in
@@ -626,7 +626,7 @@ impl FileSystem for DiskFileSystem {
626626
#[turbo_tasks::function(fs)]
627627
async fn read_link(&self, fs_path: FileSystemPath) -> Result<Vc<LinkContent>> {
628628
mark_session_dependent();
629-
let full_path = self.to_sys_path(fs_path.clone()).await?;
629+
let full_path = self.to_sys_path(fs_path.clone())?;
630630
self.inner.register_read_invalidator(&full_path)?;
631631

632632
let _lock = self.inner.lock_path(&full_path).await;
@@ -716,7 +716,7 @@ impl FileSystem for DiskFileSystem {
716716
// `write` purely declares a side effect and does not need to be reexecuted in the next
717717
// session. All side effects are reexecuted in general.
718718

719-
let full_path = self.to_sys_path(fs_path).await?;
719+
let full_path = self.to_sys_path(fs_path)?;
720720
let content = content.await?;
721721
let inner = self.inner.clone();
722722
let invalidator = turbo_tasks::get_invalidator();
@@ -851,7 +851,7 @@ impl FileSystem for DiskFileSystem {
851851
// `write_link` purely declares a side effect and does not need to be reexecuted in the next
852852
// session. All side effects are reexecuted in general.
853853

854-
let full_path = self.to_sys_path(fs_path).await?;
854+
let full_path = self.to_sys_path(fs_path)?;
855855
let content = target.await?;
856856
let inner = self.inner.clone();
857857
let invalidator = turbo_tasks::get_invalidator();
@@ -975,7 +975,7 @@ impl FileSystem for DiskFileSystem {
975975
#[turbo_tasks::function(fs)]
976976
async fn metadata(&self, fs_path: FileSystemPath) -> Result<Vc<FileMeta>> {
977977
mark_session_dependent();
978-
let full_path = self.to_sys_path(fs_path).await?;
978+
let full_path = self.to_sys_path(fs_path)?;
979979
self.inner.register_read_invalidator(&full_path)?;
980980

981981
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>> {
23082308
}
23092309

23102310
if let Some(fs) = Vc::try_resolve_downcast_type::<DiskFileSystem>(path.fs()).await? {
2311-
let sys_path = fs.await?.to_sys_path(path).await?;
2311+
let sys_path = fs.await?.to_sys_path(path)?;
23122312
return Ok(Some(sys_path));
23132313
}
23142314

turbopack/crates/turbo-tasks-fs/src/util.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ pub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<S
152152
.to_sys_path(match path {
153153
Some(path) => root.join(path)?,
154154
None => root,
155-
})
156-
.await?
155+
})?
157156
.to_string_lossy()
158157
)
159158
.split('/')
@@ -171,12 +170,10 @@ pub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<S
171170
.context("Expected root to have a DiskFileSystem")?
172171
.await?;
173172

174-
let sys_path = root_fs
175-
.to_sys_path(match path {
176-
Some(path) => root.join(path.into())?,
177-
None => root,
178-
})
179-
.await?;
173+
let sys_path = root_fs.to_sys_path(match path {
174+
Some(path) => root.join(path.into())?,
175+
None => root,
176+
})?;
180177

181178
let raw_path = sys_path.to_string_lossy().to_string();
182179
let normalized_path = raw_path.replace('\\', "/");

0 commit comments

Comments
 (0)