Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix pulling metadata out of broken symlinks (#22396)

Enrique Kessler Martínez8c215d43add4
diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs
index 07173bc8bd6..01343e4d964 100644
--- a/crates/fs/src/fs.rs
+++ b/crates/fs/src/fs.rs
@@ -4,7 +4,7 @@ mod mac_watcher;
#[cfg(not(target_os = "macos"))]
pub mod fs_watcher;
-use anyhow::{anyhow, Result};
+use anyhow::{anyhow, Context, Result};
#[cfg(any(test, feature = "test-support"))]
use git::status::FileStatus;
use git::GitHostingProviderRegistry;
@@ -589,11 +589,19 @@ impl Fs for RealFs {
}
};
+ let path_buf = path.to_path_buf();
+ let path_exists = smol::unblock(move || {
+ path_buf
+ .try_exists()
+ .with_context(|| format!("checking existence for path {path_buf:?}"))
+ })
+ .await?;
let is_symlink = symlink_metadata.file_type().is_symlink();
- let metadata = if is_symlink {
- smol::fs::metadata(path).await?
- } else {
- symlink_metadata
+ let metadata = match (is_symlink, path_exists) {
+ (true, true) => smol::fs::metadata(path)
+ .await
+ .with_context(|| "accessing symlink for path {path}")?,
+ _ => symlink_metadata,
};
#[cfg(unix)]