@@ -272,9 +272,9 @@ impl ScopedDirFileSystemInterface for mem_fs::FileSystem {}
272
272
#[ derive( Debug , Hiarc ) ]
273
273
pub struct ScopedDirFileSystem {
274
274
#[ hiarc_skip_unsafe]
275
- fs : Box < dyn ScopedDirFileSystemInterface > ,
276
- host_path : PathBuf ,
277
- mount_path : PathBuf ,
275
+ pub fs : Box < dyn ScopedDirFileSystemInterface > ,
276
+ pub host_path : PathBuf ,
277
+ pub mount_path : PathBuf ,
278
278
}
279
279
280
280
impl ScopedDirFileSystem {
@@ -311,12 +311,11 @@ pub struct FileSystem {
311
311
312
312
impl FileSystem {
313
313
#[ cfg( not( feature = "bundled_data_dir" ) ) ]
314
- fn add_data_dir ( scoped_file_systems : & mut Vec < ScopedDirFileSystem > ) -> anyhow:: Result < usize > {
315
- scoped_file_systems. push ( ScopedDirFileSystem :: new ( "data/" ) ?) ;
316
- Ok ( scoped_file_systems. len ( ) - 1 )
314
+ fn get_data_dir_fs ( ) -> anyhow:: Result < ScopedDirFileSystem > {
315
+ ScopedDirFileSystem :: new ( "data/" )
317
316
}
318
317
#[ cfg( feature = "bundled_data_dir" ) ]
319
- fn add_data_dir ( scoped_file_systems : & mut Vec < ScopedDirFileSystem > ) -> anyhow:: Result < usize > {
318
+ fn get_data_dir_fs ( ) -> anyhow:: Result < ScopedDirFileSystem > {
320
319
use virtual_fs:: AsyncWriteExt ;
321
320
const DATA_DIR : include_dir:: Dir =
322
321
include_dir:: include_dir!( "$CARGO_MANIFEST_DIR/../../data" ) ;
@@ -356,20 +355,20 @@ impl FileSystem {
356
355
357
356
add_dirs ( fs. as_ref ( ) , & DATA_DIR ) ?;
358
357
359
- scoped_file_systems . push ( ScopedDirFileSystem {
358
+ Ok ( ScopedDirFileSystem {
360
359
fs,
361
360
host_path : "data/" . into ( ) ,
362
361
mount_path : "/" . into ( ) ,
363
- } ) ;
364
- Ok ( scoped_file_systems. len ( ) - 1 )
362
+ } )
365
363
}
366
364
367
- pub fn new (
365
+ pub fn new_with_data_dir (
368
366
rt : & tokio:: runtime:: Runtime ,
369
367
qualifier : & str ,
370
368
organization : & str ,
371
369
application : & str ,
372
370
secure_appl : & str ,
371
+ data_dir : ScopedDirFileSystem ,
373
372
) -> anyhow:: Result < Self > {
374
373
let config_dir: PathBuf =
375
374
if let Some ( proj_dirs) = ProjectDirs :: from ( qualifier, organization, application) {
@@ -406,7 +405,10 @@ impl FileSystem {
406
405
log:: info!( target: "fs" , "Found config dir in {config_dir:?}" ) ;
407
406
scoped_file_systems. push ( ScopedDirFileSystem :: new ( config_dir) ?) ;
408
407
let config_dir_index = scoped_file_systems. len ( ) - 1 ;
409
- let data_dir_index = Self :: add_data_dir ( & mut scoped_file_systems) ?;
408
+
409
+ scoped_file_systems. push ( data_dir) ;
410
+ let data_dir_index = scoped_file_systems. len ( ) - 1 ;
411
+
410
412
if let Ok ( exec_path) = std:: env:: current_dir ( ) {
411
413
scoped_file_systems. push ( ScopedDirFileSystem :: new ( exec_path) ?) ;
412
414
}
@@ -428,6 +430,27 @@ impl FileSystem {
428
430
} )
429
431
}
430
432
433
+ pub fn new (
434
+ rt : & tokio:: runtime:: Runtime ,
435
+ qualifier : & str ,
436
+ organization : & str ,
437
+ application : & str ,
438
+ secure_appl : & str ,
439
+ ) -> anyhow:: Result < Self > {
440
+ let g = rt. enter ( ) ;
441
+ let data_dir = Self :: get_data_dir_fs ( ) ?;
442
+ drop ( g) ;
443
+
444
+ Self :: new_with_data_dir (
445
+ rt,
446
+ qualifier,
447
+ organization,
448
+ application,
449
+ secure_appl,
450
+ data_dir,
451
+ )
452
+ }
453
+
431
454
fn get_scoped_fs ( & self , fs_path : FileSystemPath ) -> & ScopedDirFileSystem {
432
455
let index: usize ;
433
456
match fs_path {
0 commit comments