@@ -15,6 +15,8 @@ use std::os::fd::AsRawFd;
15
15
use std:: os:: unix:: io:: FromRawFd ;
16
16
#[ cfg( windows) ]
17
17
use std:: os:: windows:: io:: FromRawHandle ;
18
+ use std:: path:: Path ;
19
+ use std:: path:: PathBuf ;
18
20
#[ cfg( unix) ]
19
21
use std:: process:: Stdio as StdStdio ;
20
22
use std:: rc:: Rc ;
@@ -255,8 +257,9 @@ deno_core::extension!(deno_io,
255
257
StdioPipeInner :: Inherit => StdFileResourceInner :: new(
256
258
StdFileResourceKind :: Stdin ( stdin_state) ,
257
259
STDIN_HANDLE . try_clone( ) . unwrap( ) ,
260
+ None ,
258
261
) ,
259
- StdioPipeInner :: File ( pipe) => StdFileResourceInner :: file( pipe) ,
262
+ StdioPipeInner :: File ( pipe) => StdFileResourceInner :: file( pipe, None ) ,
260
263
} ) ,
261
264
"stdin" . to_string( ) ,
262
265
) ) ;
@@ -267,8 +270,9 @@ deno_core::extension!(deno_io,
267
270
StdioPipeInner :: Inherit => StdFileResourceInner :: new(
268
271
StdFileResourceKind :: Stdout ,
269
272
STDOUT_HANDLE . try_clone( ) . unwrap( ) ,
273
+ None ,
270
274
) ,
271
- StdioPipeInner :: File ( pipe) => StdFileResourceInner :: file( pipe) ,
275
+ StdioPipeInner :: File ( pipe) => StdFileResourceInner :: file( pipe, None ) ,
272
276
} ) ,
273
277
"stdout" . to_string( ) ,
274
278
) ) ;
@@ -279,8 +283,9 @@ deno_core::extension!(deno_io,
279
283
StdioPipeInner :: Inherit => StdFileResourceInner :: new(
280
284
StdFileResourceKind :: Stderr ,
281
285
STDERR_HANDLE . try_clone( ) . unwrap( ) ,
286
+ None ,
282
287
) ,
283
- StdioPipeInner :: File ( pipe) => StdFileResourceInner :: file( pipe) ,
288
+ StdioPipeInner :: File ( pipe) => StdFileResourceInner :: file( pipe, None ) ,
284
289
} ) ,
285
290
"stderr" . to_string( ) ,
286
291
) ) ;
@@ -494,21 +499,27 @@ pub struct StdFileResourceInner {
494
499
// to occur at a time
495
500
cell_async_task_queue : Rc < TaskQueue > ,
496
501
handle : ResourceHandleFd ,
502
+ maybe_path : Option < PathBuf > ,
497
503
}
498
504
499
505
impl StdFileResourceInner {
500
- pub fn file ( fs_file : StdFile ) -> Self {
501
- StdFileResourceInner :: new ( StdFileResourceKind :: File , fs_file)
506
+ pub fn file ( fs_file : StdFile , maybe_path : Option < PathBuf > ) -> Self {
507
+ StdFileResourceInner :: new ( StdFileResourceKind :: File , fs_file, maybe_path )
502
508
}
503
509
504
- fn new ( kind : StdFileResourceKind , fs_file : StdFile ) -> Self {
510
+ fn new (
511
+ kind : StdFileResourceKind ,
512
+ fs_file : StdFile ,
513
+ maybe_path : Option < PathBuf > ,
514
+ ) -> Self {
505
515
// We know this will be an fd
506
516
let handle = ResourceHandle :: from_fd_like ( & fs_file) . as_fd_like ( ) . unwrap ( ) ;
507
517
StdFileResourceInner {
508
518
kind,
509
519
handle,
510
520
cell : RefCell :: new ( Some ( fs_file) ) ,
511
521
cell_async_task_queue : Default :: default ( ) ,
522
+ maybe_path,
512
523
}
513
524
}
514
525
@@ -659,6 +670,10 @@ impl StdFileResourceInner {
659
670
660
671
#[ async_trait:: async_trait( ?Send ) ]
661
672
impl crate :: fs:: File for StdFileResourceInner {
673
+ fn maybe_path ( & self ) -> Option < & Path > {
674
+ self . maybe_path . as_deref ( )
675
+ }
676
+
662
677
fn write_sync ( self : Rc < Self > , buf : & [ u8 ] ) -> FsResult < usize > {
663
678
// Rust will line buffer and we don't want that behavior
664
679
// (see https://github.com/denoland/deno/issues/948), so flush stdout and stderr.
@@ -1101,6 +1116,7 @@ impl crate::fs::File for StdFileResourceInner {
1101
1116
cell : RefCell :: new ( Some ( inner. try_clone ( ) ?) ) ,
1102
1117
cell_async_task_queue : Default :: default ( ) ,
1103
1118
handle : self . handle ,
1119
+ maybe_path : self . maybe_path . clone ( ) ,
1104
1120
} ) ) ,
1105
1121
None => Err ( FsError :: FileBusy ) ,
1106
1122
}
0 commit comments