Skip to content

Commit 04f0805

Browse files
authored
Revert "fs: Replace a bunch of uses of smol::fs with manual impls" (#40406)
Reverts #40172
1 parent 58ff469 commit 04f0805

File tree

13 files changed

+188
-432
lines changed

13 files changed

+188
-432
lines changed

Cargo.lock

Lines changed: 9 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ members = [
222222

223223
"tooling/perf",
224224
"tooling/workspace-hack",
225-
"tooling/xtask", "crates/fs_benchmarks", "crates/worktree_benchmarks",
225+
"tooling/xtask",
226226
]
227227
default-members = ["crates/zed"]
228228

@@ -455,7 +455,6 @@ async-compat = "0.2.1"
455455
async-compression = { version = "0.4", features = ["gzip", "futures-io"] }
456456
async-dispatcher = "0.1"
457457
async-fs = "2.1"
458-
async-lock = "2.1"
459458
async-pipe = { git = "https://github.com/zed-industries/async-pipe-rs", rev = "82d00a04211cf4e1236029aa03e6b6ce2a74c553" }
460459
async-recursion = "1.0.0"
461460
async-tar = "0.5.0"

crates/editor/src/editor_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12509,7 +12509,6 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut TestAppContext) {
1250912509
)
1251012510
.await;
1251112511

12512-
cx.run_until_parked();
1251312512
// Set up a buffer white some trailing whitespace and no trailing newline.
1251412513
cx.set_state(
1251512514
&[

crates/fs/src/fs.rs

Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub mod fs_watcher;
77
use anyhow::{Context as _, Result, anyhow};
88
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
99
use ashpd::desktop::trash;
10-
use futures::stream::iter;
1110
use gpui::App;
1211
use gpui::BackgroundExecutor;
1312
use gpui::Global;
@@ -563,17 +562,12 @@ impl Fs for RealFs {
563562

564563
async fn load(&self, path: &Path) -> Result<String> {
565564
let path = path.to_path_buf();
566-
self.executor
567-
.spawn(async move { Ok(std::fs::read_to_string(path)?) })
568-
.await
565+
let text = smol::unblock(|| std::fs::read_to_string(path)).await?;
566+
Ok(text)
569567
}
570-
571568
async fn load_bytes(&self, path: &Path) -> Result<Vec<u8>> {
572569
let path = path.to_path_buf();
573-
let bytes = self
574-
.executor
575-
.spawn(async move { std::fs::read(path) })
576-
.await?;
570+
let bytes = smol::unblock(|| std::fs::read(path)).await?;
577571
Ok(bytes)
578572
}
579573

@@ -641,46 +635,30 @@ impl Fs for RealFs {
641635
if let Some(path) = path.parent() {
642636
self.create_dir(path).await?;
643637
}
644-
let path = path.to_owned();
645-
let contents = content.to_owned();
646-
self.executor
647-
.spawn(async move {
648-
std::fs::write(path, contents)?;
649-
Ok(())
650-
})
651-
.await
638+
smol::fs::write(path, content).await?;
639+
Ok(())
652640
}
653641

654642
async fn canonicalize(&self, path: &Path) -> Result<PathBuf> {
655-
let path = path.to_owned();
656-
self.executor
657-
.spawn(async move {
658-
std::fs::canonicalize(&path).with_context(|| format!("canonicalizing {path:?}"))
659-
})
643+
Ok(smol::fs::canonicalize(path)
660644
.await
645+
.with_context(|| format!("canonicalizing {path:?}"))?)
661646
}
662647

663648
async fn is_file(&self, path: &Path) -> bool {
664-
let path = path.to_owned();
665-
self.executor
666-
.spawn(async move { std::fs::metadata(path).is_ok_and(|metadata| metadata.is_file()) })
649+
smol::fs::metadata(path)
667650
.await
651+
.is_ok_and(|metadata| metadata.is_file())
668652
}
669653

670654
async fn is_dir(&self, path: &Path) -> bool {
671-
let path = path.to_owned();
672-
self.executor
673-
.spawn(async move { std::fs::metadata(path).is_ok_and(|metadata| metadata.is_dir()) })
655+
smol::fs::metadata(path)
674656
.await
657+
.is_ok_and(|metadata| metadata.is_dir())
675658
}
676659

677660
async fn metadata(&self, path: &Path) -> Result<Option<Metadata>> {
678-
let path_buf = path.to_owned();
679-
let symlink_metadata = match self
680-
.executor
681-
.spawn(async move { std::fs::symlink_metadata(&path_buf) })
682-
.await
683-
{
661+
let symlink_metadata = match smol::fs::symlink_metadata(path).await {
684662
Ok(metadata) => metadata,
685663
Err(err) => {
686664
return match (err.kind(), err.raw_os_error()) {
@@ -691,28 +669,19 @@ impl Fs for RealFs {
691669
}
692670
};
693671

672+
let path_buf = path.to_path_buf();
673+
let path_exists = smol::unblock(move || {
674+
path_buf
675+
.try_exists()
676+
.with_context(|| format!("checking existence for path {path_buf:?}"))
677+
})
678+
.await?;
694679
let is_symlink = symlink_metadata.file_type().is_symlink();
695-
let metadata = if is_symlink {
696-
let path_buf = path.to_path_buf();
697-
let path_exists = self
698-
.executor
699-
.spawn(async move {
700-
path_buf
701-
.try_exists()
702-
.with_context(|| format!("checking existence for path {path_buf:?}"))
703-
})
704-
.await?;
705-
if path_exists {
706-
let path_buf = path.to_path_buf();
707-
self.executor
708-
.spawn(async move { std::fs::metadata(path_buf) })
709-
.await
710-
.with_context(|| "accessing symlink for path {path}")?
711-
} else {
712-
symlink_metadata
713-
}
714-
} else {
715-
symlink_metadata
680+
let metadata = match (is_symlink, path_exists) {
681+
(true, true) => smol::fs::metadata(path)
682+
.await
683+
.with_context(|| "accessing symlink for path {path}")?,
684+
_ => symlink_metadata,
716685
};
717686

718687
#[cfg(unix)]
@@ -738,25 +707,15 @@ impl Fs for RealFs {
738707
}
739708

740709
async fn read_link(&self, path: &Path) -> Result<PathBuf> {
741-
let path = path.to_owned();
742-
let path = self
743-
.executor
744-
.spawn(async move { std::fs::read_link(&path) })
745-
.await?;
710+
let path = smol::fs::read_link(path).await?;
746711
Ok(path)
747712
}
748713

749714
async fn read_dir(
750715
&self,
751716
path: &Path,
752717
) -> Result<Pin<Box<dyn Send + Stream<Item = Result<PathBuf>>>>> {
753-
let path = path.to_owned();
754-
let result = iter(
755-
self.executor
756-
.spawn(async move { std::fs::read_dir(path) })
757-
.await?,
758-
)
759-
.map(|entry| match entry {
718+
let result = smol::fs::read_dir(path).await?.map(|entry| match entry {
760719
Ok(entry) => Ok(entry.path()),
761720
Err(error) => Err(anyhow!("failed to read dir entry {error:?}")),
762721
});

crates/fs_benchmarks/Cargo.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

crates/fs_benchmarks/LICENSE-GPL

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/fs_benchmarks/src/main.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

crates/worktree/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ test-support = [
2424

2525
[dependencies]
2626
anyhow.workspace = true
27-
async-lock.workspace = true
2827
clock.workspace = true
2928
collections.workspace = true
3029
fs.workspace = true

0 commit comments

Comments
 (0)