@@ -373,15 +373,21 @@ impl File {
373373/// Creates a drive with path "/package_id/drive", gives you read and write caps.
374374/// Will only work on the same package_id as you're calling it from, unless you
375375/// have root capabilities.
376- pub fn create_drive ( package_id : PackageId , drive : & str ) -> anyhow:: Result < String > {
376+ pub fn create_drive (
377+ package_id : PackageId ,
378+ drive : & str ,
379+ timeout : Option < u64 > ,
380+ ) -> anyhow:: Result < String > {
381+ let timeout = timeout. unwrap_or ( 5 ) ;
382+
377383 let path = format ! ( "/{}/{}" , package_id, drive) ;
378384 let res = Request :: new ( )
379385 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
380386 . body ( serde_json:: to_vec ( & VfsRequest {
381387 path : path. clone ( ) ,
382388 action : VfsAction :: CreateDrive ,
383389 } ) ?)
384- . send_and_await_response ( 5 ) ?;
390+ . send_and_await_response ( timeout ) ?;
385391
386392 match res {
387393 Ok ( Message :: Response { body, .. } ) => {
@@ -397,7 +403,9 @@ pub fn create_drive(package_id: PackageId, drive: &str) -> anyhow::Result<String
397403}
398404
399405/// Opens a file at path, if no file at path, creates one if boolean create is true.
400- pub fn open_file ( path : & str , create : bool ) -> anyhow:: Result < File > {
406+ pub fn open_file ( path : & str , create : bool , timeout : Option < u64 > ) -> anyhow:: Result < File > {
407+ let timeout = timeout. unwrap_or ( 5 ) ;
408+
401409 let request = VfsRequest {
402410 path : path. to_string ( ) ,
403411 action : VfsAction :: OpenFile { create } ,
@@ -406,15 +414,15 @@ pub fn open_file(path: &str, create: bool) -> anyhow::Result<File> {
406414 let message = Request :: new ( )
407415 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
408416 . body ( serde_json:: to_vec ( & request) ?)
409- . send_and_await_response ( 5 ) ?;
417+ . send_and_await_response ( timeout ) ?;
410418
411419 match message {
412420 Ok ( Message :: Response { body, .. } ) => {
413421 let response = serde_json:: from_slice :: < VfsResponse > ( & body) ?;
414422 match response {
415423 VfsResponse :: Ok => Ok ( File {
416424 path : path. to_string ( ) ,
417- timeout : 5 ,
425+ timeout,
418426 } ) ,
419427 VfsResponse :: Err ( e) => Err ( e. into ( ) ) ,
420428 _ => Err ( anyhow:: anyhow!( "vfs: unexpected response: {:?}" , response) ) ,
@@ -454,7 +462,9 @@ pub fn create_file(path: &str, timeout: Option<u64>) -> anyhow::Result<File> {
454462}
455463
456464/// Removes a file at path, errors if path not found or path is not a file.
457- pub fn remove_file ( path : & str ) -> anyhow:: Result < ( ) > {
465+ pub fn remove_file ( path : & str , timeout : Option < u64 > ) -> anyhow:: Result < ( ) > {
466+ let timeout = timeout. unwrap_or ( 5 ) ;
467+
458468 let request = VfsRequest {
459469 path : path. to_string ( ) ,
460470 action : VfsAction :: RemoveFile ,
@@ -463,7 +473,7 @@ pub fn remove_file(path: &str) -> anyhow::Result<()> {
463473 let message = Request :: new ( )
464474 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
465475 . body ( serde_json:: to_vec ( & request) ?)
466- . send_and_await_response ( 5 ) ?;
476+ . send_and_await_response ( timeout ) ?;
467477
468478 match message {
469479 Ok ( Message :: Response { body, .. } ) => {
0 commit comments