@@ -311,45 +311,14 @@ impl DiskFileSystem {
311
311
312
312
Ok ( Self :: cell ( instance) )
313
313
}
314
- }
315
-
316
- impl Debug for DiskFileSystem {
317
- fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
318
- write ! ( f, "name: {}, root: {}" , self . name, self . root)
319
- }
320
- }
321
314
322
- #[ turbo_tasks:: value_impl]
323
- impl FileSystem for DiskFileSystem {
324
315
#[ turbo_tasks:: function( fs) ]
325
- async fn read ( & self , fs_path : Vc < FileSystemPath > ) -> Result < Vc < FileContent > > {
326
- let full_path = self . to_sys_path ( fs_path) . await ?;
327
- self . register_invalidator ( & full_path) ?;
328
-
329
- let _lock = self . lock_path ( & full_path) . await ;
330
- let content = match retry_future ( || File :: from_path ( full_path. clone ( ) ) )
331
- . instrument ( tracing:: info_span!(
332
- "read file" ,
333
- path = display( full_path. display( ) )
334
- ) )
335
- . await
336
- {
337
- Ok ( file) => FileContent :: new ( file) ,
338
- Err ( e) if e. kind ( ) == ErrorKind :: NotFound || e. kind ( ) == ErrorKind :: InvalidFilename => {
339
- FileContent :: NotFound
340
- }
341
- Err ( e) => {
342
- bail ! ( anyhow!( e) . context( format!( "reading file {}" , full_path. display( ) ) ) )
343
- }
344
- } ;
345
- Ok ( content. cell ( ) )
346
- }
347
-
348
- #[ turbo_tasks:: function( fs) ]
349
- async fn read_dir ( & self , fs_path : Vc < FileSystemPath > ) -> Result < Vc < DirectoryContent > > {
316
+ async fn read_dir_internal (
317
+ & self ,
318
+ fs_path : Vc < FileSystemPath > ,
319
+ ) -> Result < Vc < InternalDirectoryContent > > {
350
320
let full_path = self . to_sys_path ( fs_path) . await ?;
351
321
self . register_dir_invalidator ( & full_path) ?;
352
- let fs_path = fs_path. await ?;
353
322
354
323
// we use the sync std function here as it's a lot faster (600%) in
355
324
// node-file-trace
@@ -366,7 +335,7 @@ impl FileSystem for DiskFileSystem {
366
335
|| e. kind ( ) == ErrorKind :: NotADirectory
367
336
|| e. kind ( ) == ErrorKind :: InvalidFilename =>
368
337
{
369
- return Ok ( DirectoryContent :: not_found ( ) ) ;
338
+ return Ok ( InternalDirectoryContent :: not_found ( ) ) ;
370
339
}
371
340
Err ( e) => {
372
341
bail ! ( anyhow!( e) . context( format!( "reading dir {}" , full_path. display( ) ) ) )
@@ -386,13 +355,13 @@ impl FileSystem for DiskFileSystem {
386
355
let file_name: RcStr = path. file_name ( ) ?. to_str ( ) ?. into ( ) ;
387
356
let path_to_root = sys_to_unix ( path. strip_prefix ( & self . root ) . ok ( ) ?. to_str ( ) ?) ;
388
357
389
- let fs_path = FileSystemPath :: new_normalized ( fs_path . fs , path_to_root. into ( ) ) ;
358
+ let path = path_to_root. into ( ) ;
390
359
391
360
let entry = match e. file_type ( ) {
392
- Ok ( t) if t. is_file ( ) => DirectoryEntry :: File ( fs_path ) ,
393
- Ok ( t) if t. is_dir ( ) => DirectoryEntry :: Directory ( fs_path ) ,
394
- Ok ( t) if t. is_symlink ( ) => DirectoryEntry :: Symlink ( fs_path ) ,
395
- Ok ( _) => DirectoryEntry :: Other ( fs_path ) ,
361
+ Ok ( t) if t. is_file ( ) => InternalDirectoryEntry :: File ( path ) ,
362
+ Ok ( t) if t. is_dir ( ) => InternalDirectoryEntry :: Directory ( path ) ,
363
+ Ok ( t) if t. is_symlink ( ) => InternalDirectoryEntry :: Symlink ( path ) ,
364
+ Ok ( _) => InternalDirectoryEntry :: Other ( path ) ,
396
365
Err ( err) => return Some ( Err ( err. into ( ) ) ) ,
397
366
} ;
398
367
@@ -401,7 +370,72 @@ impl FileSystem for DiskFileSystem {
401
370
. collect :: < Result < _ > > ( )
402
371
. with_context ( || format ! ( "reading directory item in {}" , full_path. display( ) ) ) ?;
403
372
404
- Ok ( DirectoryContent :: new ( entries) )
373
+ Ok ( InternalDirectoryContent :: new ( entries) )
374
+ }
375
+ }
376
+
377
+ impl Debug for DiskFileSystem {
378
+ fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
379
+ write ! ( f, "name: {}, root: {}" , self . name, self . root)
380
+ }
381
+ }
382
+
383
+ #[ turbo_tasks:: value_impl]
384
+ impl FileSystem for DiskFileSystem {
385
+ #[ turbo_tasks:: function( fs) ]
386
+ async fn read ( & self , fs_path : Vc < FileSystemPath > ) -> Result < Vc < FileContent > > {
387
+ let full_path = self . to_sys_path ( fs_path) . await ?;
388
+ self . register_invalidator ( & full_path) ?;
389
+
390
+ let _lock = self . lock_path ( & full_path) . await ;
391
+ let content = match retry_future ( || File :: from_path ( full_path. clone ( ) ) )
392
+ . instrument ( tracing:: info_span!(
393
+ "read file" ,
394
+ path = display( full_path. display( ) )
395
+ ) )
396
+ . await
397
+ {
398
+ Ok ( file) => FileContent :: new ( file) ,
399
+ Err ( e) if e. kind ( ) == ErrorKind :: NotFound || e. kind ( ) == ErrorKind :: InvalidFilename => {
400
+ FileContent :: NotFound
401
+ }
402
+ Err ( e) => {
403
+ bail ! ( anyhow!( e) . context( format!( "reading file {}" , full_path. display( ) ) ) )
404
+ }
405
+ } ;
406
+ Ok ( content. cell ( ) )
407
+ }
408
+
409
+ #[ turbo_tasks:: function]
410
+ async fn read_dir ( self : Vc < Self > , fs_path : Vc < FileSystemPath > ) -> Result < Vc < DirectoryContent > > {
411
+ match & * self . read_dir_internal ( fs_path) . await ? {
412
+ InternalDirectoryContent :: NotFound => Ok ( DirectoryContent :: not_found ( ) ) ,
413
+ InternalDirectoryContent :: Entries ( entries) => {
414
+ let fs = fs_path. await ?. fs ;
415
+ let entries = entries
416
+ . iter ( )
417
+ . map ( |( name, entry) | {
418
+ let entry = match entry {
419
+ InternalDirectoryEntry :: File ( path) => DirectoryEntry :: File (
420
+ FileSystemPath :: new_normalized ( fs, path. clone ( ) ) ,
421
+ ) ,
422
+ InternalDirectoryEntry :: Directory ( path) => DirectoryEntry :: Directory (
423
+ FileSystemPath :: new_normalized ( fs, path. clone ( ) ) ,
424
+ ) ,
425
+ InternalDirectoryEntry :: Symlink ( path) => DirectoryEntry :: Symlink (
426
+ FileSystemPath :: new_normalized ( fs, path. clone ( ) ) ,
427
+ ) ,
428
+ InternalDirectoryEntry :: Other ( path) => DirectoryEntry :: Other (
429
+ FileSystemPath :: new_normalized ( fs, path. clone ( ) ) ,
430
+ ) ,
431
+ InternalDirectoryEntry :: Error => DirectoryEntry :: Error ,
432
+ } ;
433
+ ( name. clone ( ) , entry)
434
+ } )
435
+ . collect ( ) ;
436
+ Ok ( DirectoryContent :: new ( entries) )
437
+ }
438
+ }
405
439
}
406
440
407
441
#[ turbo_tasks:: function( fs) ]
@@ -1849,6 +1883,15 @@ pub enum FileLinesContent {
1849
1883
NotFound ,
1850
1884
}
1851
1885
1886
+ #[ derive( Hash , Clone , Debug , PartialEq , Eq , TraceRawVcs , Serialize , Deserialize ) ]
1887
+ pub enum InternalDirectoryEntry {
1888
+ File ( RcStr ) ,
1889
+ Directory ( RcStr ) ,
1890
+ Symlink ( RcStr ) ,
1891
+ Other ( RcStr ) ,
1892
+ Error ,
1893
+ }
1894
+
1852
1895
#[ derive( Hash , Clone , Copy , Debug , PartialEq , Eq , TraceRawVcs , Serialize , Deserialize ) ]
1853
1896
pub enum DirectoryEntry {
1854
1897
File ( Vc < FileSystemPath > ) ,
@@ -1916,6 +1959,23 @@ impl From<&DirectoryEntry> for FileSystemEntryType {
1916
1959
}
1917
1960
}
1918
1961
1962
+ #[ turbo_tasks:: value]
1963
+ #[ derive( Debug ) ]
1964
+ pub enum InternalDirectoryContent {
1965
+ Entries ( Vec < ( RcStr , InternalDirectoryEntry ) > ) ,
1966
+ NotFound ,
1967
+ }
1968
+
1969
+ impl InternalDirectoryContent {
1970
+ pub fn new ( entries : Vec < ( RcStr , InternalDirectoryEntry ) > ) -> Vc < Self > {
1971
+ Self :: cell ( InternalDirectoryContent :: Entries ( entries) )
1972
+ }
1973
+
1974
+ pub fn not_found ( ) -> Vc < Self > {
1975
+ Self :: cell ( InternalDirectoryContent :: NotFound )
1976
+ }
1977
+ }
1978
+
1919
1979
#[ turbo_tasks:: value]
1920
1980
#[ derive( Debug ) ]
1921
1981
pub enum DirectoryContent {
0 commit comments