@@ -7,7 +7,6 @@ pub mod fs_watcher;
77use anyhow:: { Context as _, Result , anyhow} ;
88#[ cfg( any( target_os = "linux" , target_os = "freebsd" ) ) ]
99use ashpd:: desktop:: trash;
10- use futures:: stream:: iter;
1110use gpui:: App ;
1211use gpui:: BackgroundExecutor ;
1312use 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 } ) ;
0 commit comments