Skip to content

Commit c68c59a

Browse files
committed
Revert "Experiment: Bundle metadata with directory info"
This reverts commit d0fcfe7.
1 parent 87fa7b7 commit c68c59a

File tree

4 files changed

+37
-94
lines changed

4 files changed

+37
-94
lines changed

crates/fs/src/fs.rs

Lines changed: 27 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use gpui::App;
1212
use gpui::BackgroundExecutor;
1313
use gpui::Global;
1414
use gpui::ReadGlobal as _;
15-
use smol::stream::StreamExt;
1615
use std::borrow::Cow;
1716
use util::command::new_smol_command;
1817

@@ -26,7 +25,7 @@ use std::os::unix::fs::{FileTypeExt, MetadataExt};
2625
use std::mem::MaybeUninit;
2726

2827
use async_tar::Archive;
29-
use futures::{AsyncRead, Stream, future::BoxFuture};
28+
use futures::{AsyncRead, Stream, StreamExt, future::BoxFuture};
3029
use git::repository::{GitRepository, RealGitRepository};
3130
use rope::Rope;
3231
use serde::{Deserialize, Serialize};
@@ -125,7 +124,7 @@ pub trait Fs: Send + Sync {
125124
async fn read_dir(
126125
&self,
127126
path: &Path,
128-
) -> Result<Pin<Box<dyn Send + Stream<Item = Result<DirEntry>>>>>;
127+
) -> Result<Pin<Box<dyn Send + Stream<Item = Result<PathBuf>>>>>;
129128

130129
async fn watch(
131130
&self,
@@ -153,49 +152,6 @@ pub trait Fs: Send + Sync {
153152
}
154153
}
155154

156-
enum DirEntryPayload {
157-
Entry(Option<std::fs::DirEntry>),
158-
Metadata(Result<Metadata>),
159-
}
160-
pub struct DirEntry {
161-
path: Arc<Path>,
162-
payload: DirEntryPayload,
163-
executor: BackgroundExecutor,
164-
}
165-
166-
impl DirEntry {
167-
fn new(entry: std::fs::DirEntry, executor: BackgroundExecutor) -> Self {
168-
let path = entry.path().into();
169-
170-
Self {
171-
path,
172-
payload: DirEntryPayload::Entry(Some(entry)),
173-
executor,
174-
}
175-
}
176-
pub async fn metadata(&mut self) -> &Result<Metadata> {
177-
if let DirEntryPayload::Entry(entry) = &mut self.payload {
178-
let dir_entry = entry.take().unwrap();
179-
let meta = self
180-
.executor
181-
.spawn(async move { dir_entry.metadata() })
182-
.await;
183-
let is_symlink = meta.as_ref().ok().is_some_and(|meta| meta.is_symlink());
184-
let payload = match meta {
185-
Ok(meta) => RealFs::std_meta_to_zed_metadata(&self.path, meta, is_symlink).await,
186-
Err(e) => Err(e.into()),
187-
};
188-
self.payload = DirEntryPayload::Metadata(payload);
189-
}
190-
let DirEntryPayload::Metadata(meta) = &self.payload else {
191-
unreachable!();
192-
};
193-
meta
194-
}
195-
pub fn path(&self) -> &Arc<Path> {
196-
&self.path
197-
}
198-
}
199155
struct GlobalFs(Arc<dyn Fs>);
200156

201157
impl Global for GlobalFs {}
@@ -378,32 +334,6 @@ impl RealFs {
378334
executor,
379335
}
380336
}
381-
async fn std_meta_to_zed_metadata(
382-
_path: &Path,
383-
metadata: std::fs::Metadata,
384-
is_symlink: bool,
385-
) -> Result<Metadata> {
386-
#[cfg(unix)]
387-
let inode = metadata.ino();
388-
389-
#[cfg(windows)]
390-
let inode = file_id(_path).await?;
391-
392-
#[cfg(windows)]
393-
let is_fifo = false;
394-
395-
#[cfg(unix)]
396-
let is_fifo = metadata.file_type().is_fifo();
397-
398-
Ok(Metadata {
399-
inode,
400-
mtime: MTime(metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH)),
401-
len: metadata.len(),
402-
is_symlink,
403-
is_dir: metadata.file_type().is_dir(),
404-
is_fifo,
405-
})
406-
}
407337
}
408338

409339
#[async_trait::async_trait]
@@ -784,9 +714,27 @@ impl Fs for RealFs {
784714
} else {
785715
symlink_metadata
786716
};
787-
Self::std_meta_to_zed_metadata(path, metadata, is_symlink)
788-
.await
789-
.map(Some)
717+
718+
#[cfg(unix)]
719+
let inode = metadata.ino();
720+
721+
#[cfg(windows)]
722+
let inode = file_id(path).await?;
723+
724+
#[cfg(windows)]
725+
let is_fifo = false;
726+
727+
#[cfg(unix)]
728+
let is_fifo = metadata.file_type().is_fifo();
729+
730+
Ok(Some(Metadata {
731+
inode,
732+
mtime: MTime(metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH)),
733+
len: metadata.len(),
734+
is_symlink,
735+
is_dir: metadata.file_type().is_dir(),
736+
is_fifo,
737+
}))
790738
}
791739

792740
async fn read_link(&self, path: &Path) -> Result<PathBuf> {
@@ -801,17 +749,15 @@ impl Fs for RealFs {
801749
async fn read_dir(
802750
&self,
803751
path: &Path,
804-
) -> Result<Pin<Box<dyn Send + Stream<Item = Result<DirEntry>>>>> {
752+
) -> Result<Pin<Box<dyn Send + Stream<Item = Result<PathBuf>>>>> {
805753
let path = path.to_owned();
806-
807-
let executor = self.executor.clone();
808754
let result = iter(
809755
self.executor
810756
.spawn(async move { std::fs::read_dir(path) })
811757
.await?,
812758
)
813-
.map(move |entry| match entry {
814-
Ok(entry) => Ok(DirEntry::new(entry, executor.clone())),
759+
.map(|entry| match entry {
760+
Ok(entry) => Ok(entry.path()),
815761
Err(error) => Err(anyhow!("failed to read dir entry {error:?}")),
816762
});
817763
Ok(Box::pin(result))
@@ -2704,7 +2650,7 @@ fn read_recursive<'a>(
27042650
let mut children = fs.read_dir(source).await?;
27052651
while let Some(child_path) = children.next().await {
27062652
if let Ok(child_path) = child_path {
2707-
read_recursive(fs, &child_path.path(), output).await?;
2653+
read_recursive(fs, &child_path, output).await?;
27082654
}
27092655
}
27102656
} else {

crates/prompt_store/src/prompts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ impl PromptBuilder {
264264
// Initial scan of the prompt overrides directory
265265
if let Ok(mut entries) = params.fs.read_dir(&templates_dir).await {
266266
while let Some(Ok(file_path)) = entries.next().await {
267-
let file_path = file_path.path();
268267
if file_path.to_string_lossy().ends_with(".hbs")
269268
&& let Ok(content) = params.fs.load(&file_path).await {
270269
let file_name = file_path.file_stem().unwrap().to_string_lossy();

crates/theme/src/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl ThemeRegistry {
220220
continue;
221221
};
222222

223-
self.load_user_theme(&theme_path.path(), fs.clone())
223+
self.load_user_theme(&theme_path, fs.clone())
224224
.await
225225
.log_err();
226226
}

crates/worktree/src/worktree.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ mod worktree_settings;
33
#[cfg(test)]
44
mod worktree_tests;
55

6-
use ::ignore::{
7-
DirEntry,
8-
gitignore::{Gitignore, GitignoreBuilder},
9-
};
6+
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
107
use anyhow::{Context as _, Result, anyhow};
118
use clock::ReplicaId;
129
use collections::{HashMap, HashSet, VecDeque};
@@ -4182,13 +4179,13 @@ impl BackgroundScanner {
41824179
swap_to_front(&mut child_paths, DOT_GIT);
41834180

41844181
if let Some(path) = child_paths.first()
4185-
&& path.path().ends_with(DOT_GIT)
4182+
&& path.ends_with(DOT_GIT)
41864183
{
41874184
ignore_stack.repo_root = Some(job.abs_path.clone());
41884185
}
41894186

4190-
for mut child in child_paths {
4191-
let child_abs_path: Arc<Path> = child.path().clone();
4187+
for child_abs_path in child_paths {
4188+
let child_abs_path: Arc<Path> = child_abs_path.into();
41924189
let child_name = child_abs_path.file_name().unwrap();
41934190
let Some(child_path) = child_name
41944191
.to_str()
@@ -4229,8 +4226,9 @@ impl BackgroundScanner {
42294226
continue;
42304227
}
42314228

4232-
let child_metadata = match child.metadata().await {
4233-
Ok(metadata) => metadata,
4229+
let child_metadata = match self.fs.metadata(&child_abs_path).await {
4230+
Ok(Some(metadata)) => metadata,
4231+
Ok(None) => continue,
42344232
Err(err) => {
42354233
log::error!("error processing {child_abs_path:?}: {err:?}");
42364234
continue;
@@ -5007,10 +5005,10 @@ fn build_diff(
50075005
changes.into()
50085006
}
50095007

5010-
fn swap_to_front(child_paths: &mut Vec<fs::DirEntry>, file: &str) {
5008+
fn swap_to_front(child_paths: &mut Vec<PathBuf>, file: &str) {
50115009
let position = child_paths
50125010
.iter()
5013-
.position(|path| path.path().file_name().unwrap() == file);
5011+
.position(|path| path.file_name().unwrap() == file);
50145012
if let Some(position) = position {
50155013
let temp = child_paths.remove(position);
50165014
child_paths.insert(0, temp);

0 commit comments

Comments
 (0)