@@ -12,7 +12,6 @@ use gpui::App;
1212use gpui:: BackgroundExecutor ;
1313use gpui:: Global ;
1414use gpui:: ReadGlobal as _;
15- use smol:: stream:: StreamExt ;
1615use std:: borrow:: Cow ;
1716use util:: command:: new_smol_command;
1817
@@ -26,7 +25,7 @@ use std::os::unix::fs::{FileTypeExt, MetadataExt};
2625use std:: mem:: MaybeUninit ;
2726
2827use async_tar:: Archive ;
29- use futures:: { AsyncRead , Stream , future:: BoxFuture } ;
28+ use futures:: { AsyncRead , Stream , StreamExt , future:: BoxFuture } ;
3029use git:: repository:: { GitRepository , RealGitRepository } ;
3130use rope:: Rope ;
3231use 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- }
199155struct GlobalFs ( Arc < dyn Fs > ) ;
200156
201157impl 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 {
0 commit comments