@@ -6,6 +6,7 @@ use crate::{get_blob, Message, PackageId, Request};
66/// You can call it's impl functions to interact with it.
77pub struct File {
88 pub path : String ,
9+ pub timeout : u64 ,
910}
1011
1112impl File {
@@ -19,7 +20,7 @@ impl File {
1920 let message = Request :: new ( )
2021 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
2122 . body ( serde_json:: to_vec ( & request) ?)
22- . send_and_await_response ( 5 ) ?;
23+ . send_and_await_response ( self . timeout ) ?;
2324
2425 match message {
2526 Ok ( Message :: Response { body, .. } ) => {
@@ -50,7 +51,7 @@ impl File {
5051 let message = Request :: new ( )
5152 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
5253 . body ( serde_json:: to_vec ( & request) ?)
53- . send_and_await_response ( 5 ) ?;
54+ . send_and_await_response ( self . timeout ) ?;
5455
5556 match message {
5657 Ok ( Message :: Response { body, .. } ) => {
@@ -84,7 +85,7 @@ impl File {
8485 let message = Request :: new ( )
8586 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
8687 . body ( serde_json:: to_vec ( & request) ?)
87- . send_and_await_response ( 5 ) ?;
88+ . send_and_await_response ( self . timeout ) ?;
8889
8990 match message {
9091 Ok ( Message :: Response { body, .. } ) => {
@@ -117,7 +118,7 @@ impl File {
117118 let message = Request :: new ( )
118119 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
119120 . body ( serde_json:: to_vec ( & request) ?)
120- . send_and_await_response ( 5 ) ?;
121+ . send_and_await_response ( self . timeout ) ?;
121122
122123 match message {
123124 Ok ( Message :: Response { body, .. } ) => {
@@ -149,7 +150,7 @@ impl File {
149150 let message = Request :: new ( )
150151 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
151152 . body ( serde_json:: to_vec ( & request) ?)
152- . send_and_await_response ( 5 ) ?;
153+ . send_and_await_response ( self . timeout ) ?;
153154
154155 match message {
155156 Ok ( Message :: Response { body, .. } ) => {
@@ -176,7 +177,7 @@ impl File {
176177 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
177178 . body ( serde_json:: to_vec ( & request) ?)
178179 . blob_bytes ( buffer)
179- . send_and_await_response ( 5 ) ?;
180+ . send_and_await_response ( self . timeout ) ?;
180181
181182 match message {
182183 Ok ( Message :: Response { body, .. } ) => {
@@ -201,7 +202,7 @@ impl File {
201202 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
202203 . body ( serde_json:: to_vec ( & request) ?)
203204 . blob_bytes ( buffer)
204- . send_and_await_response ( 5 ) ?;
205+ . send_and_await_response ( self . timeout ) ?;
205206
206207 match message {
207208 Ok ( Message :: Response { body, .. } ) => {
@@ -226,7 +227,7 @@ impl File {
226227 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
227228 . body ( serde_json:: to_vec ( & request) ?)
228229 . blob_bytes ( buffer)
229- . send_and_await_response ( 5 ) ?;
230+ . send_and_await_response ( self . timeout ) ?;
230231
231232 match message {
232233 Ok ( Message :: Response { body, .. } ) => {
@@ -251,7 +252,7 @@ impl File {
251252 let message = Request :: new ( )
252253 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
253254 . body ( serde_json:: to_vec ( & request) ?)
254- . send_and_await_response ( 5 ) ?;
255+ . send_and_await_response ( self . timeout ) ?;
255256
256257 match message {
257258 Ok ( Message :: Response { body, .. } ) => {
@@ -286,6 +287,7 @@ impl File {
286287 match response {
287288 VfsResponse :: Ok => Ok ( File {
288289 path : path. to_string ( ) ,
290+ timeout : self . timeout ,
289291 } ) ,
290292 VfsResponse :: Err ( e) => Err ( e. into ( ) ) ,
291293 _ => Err ( anyhow:: anyhow!( "vfs: unexpected response: {:?}" , response) ) ,
@@ -304,7 +306,7 @@ impl File {
304306 let message = Request :: new ( )
305307 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
306308 . body ( serde_json:: to_vec ( & request) ?)
307- . send_and_await_response ( 5 ) ?;
309+ . send_and_await_response ( self . timeout ) ?;
308310
309311 match message {
310312 Ok ( Message :: Response { body, .. } ) => {
@@ -328,7 +330,7 @@ impl File {
328330 let message = Request :: new ( )
329331 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
330332 . body ( serde_json:: to_vec ( & request) ?)
331- . send_and_await_response ( 5 ) ?;
333+ . send_and_await_response ( self . timeout ) ?;
332334
333335 match message {
334336 Ok ( Message :: Response { body, .. } ) => {
@@ -352,7 +354,7 @@ impl File {
352354 let message = Request :: new ( )
353355 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
354356 . body ( serde_json:: to_vec ( & request) ?)
355- . send_and_await_response ( 5 ) ?;
357+ . send_and_await_response ( self . timeout ) ?;
356358
357359 match message {
358360 Ok ( Message :: Response { body, .. } ) => {
@@ -412,6 +414,7 @@ pub fn open_file(path: &str, create: bool) -> anyhow::Result<File> {
412414 match response {
413415 VfsResponse :: Ok => Ok ( File {
414416 path : path. to_string ( ) ,
417+ timeout : 5 ,
415418 } ) ,
416419 VfsResponse :: Err ( e) => Err ( e. into ( ) ) ,
417420 _ => Err ( anyhow:: anyhow!( "vfs: unexpected response: {:?}" , response) ) ,
@@ -422,7 +425,8 @@ pub fn open_file(path: &str, create: bool) -> anyhow::Result<File> {
422425}
423426
424427/// Creates a file at path, if file found at path, truncates it to 0.
425- pub fn create_file ( path : & str ) -> anyhow:: Result < File > {
428+ pub fn create_file ( path : & str , timeout : Option < u64 > ) -> anyhow:: Result < File > {
429+ let timeout = timeout. unwrap_or ( 5 ) ;
426430 let request = VfsRequest {
427431 path : path. to_string ( ) ,
428432 action : VfsAction :: CreateFile ,
@@ -431,14 +435,15 @@ pub fn create_file(path: &str) -> anyhow::Result<File> {
431435 let message = Request :: new ( )
432436 . target ( ( "our" , "vfs" , "distro" , "sys" ) )
433437 . body ( serde_json:: to_vec ( & request) ?)
434- . send_and_await_response ( 5 ) ?;
438+ . send_and_await_response ( timeout ) ?;
435439
436440 match message {
437441 Ok ( Message :: Response { body, .. } ) => {
438442 let response = serde_json:: from_slice :: < VfsResponse > ( & body) ?;
439443 match response {
440444 VfsResponse :: Ok => Ok ( File {
441445 path : path. to_string ( ) ,
446+ timeout,
442447 } ) ,
443448 VfsResponse :: Err ( e) => Err ( e. into ( ) ) ,
444449 _ => Err ( anyhow:: anyhow!( "vfs: unexpected response: {:?}" , response) ) ,
0 commit comments