@@ -1772,13 +1772,20 @@ pub async fn op_fs_file_sync_async(
17721772}
17731773
17741774#[ op2( fast) ]
1775- pub fn op_fs_file_stat_sync (
1775+ pub fn op_fs_file_stat_sync < P : FsPermissions + ' static > (
17761776 state : & mut OpState ,
17771777 #[ smi] rid : ResourceId ,
17781778 #[ buffer] stat_out_buf : & mut [ u32 ] ,
17791779) -> Result < ( ) , FsOpsError > {
17801780 let file =
17811781 FileResource :: get_file ( state, rid) . map_err ( FsOpsErrorKind :: Resource ) ?;
1782+ if let Some ( path) = file. maybe_path ( ) {
1783+ _ = state. borrow :: < P > ( ) . check_open (
1784+ Cow :: Borrowed ( path) ,
1785+ OpenAccessKind :: Read ,
1786+ "Deno.FsFile.prototype.statSync()" ,
1787+ ) ?;
1788+ }
17821789 let stat = file. stat_sync ( ) ?;
17831790 let serializable_stat = SerializableStat :: from ( stat) ;
17841791 serializable_stat. write ( stat_out_buf) ;
@@ -1787,12 +1794,19 @@ pub fn op_fs_file_stat_sync(
17871794
17881795#[ op2( async ) ]
17891796#[ serde]
1790- pub async fn op_fs_file_stat_async (
1797+ pub async fn op_fs_file_stat_async < P : FsPermissions + ' static > (
17911798 state : Rc < RefCell < OpState > > ,
17921799 #[ smi] rid : ResourceId ,
17931800) -> Result < SerializableStat , FsOpsError > {
17941801 let file = FileResource :: get_file ( & state. borrow ( ) , rid)
17951802 . map_err ( FsOpsErrorKind :: Resource ) ?;
1803+ if let Some ( path) = file. maybe_path ( ) {
1804+ _ = state. borrow ( ) . borrow :: < P > ( ) . check_open (
1805+ Cow :: Borrowed ( path) ,
1806+ OpenAccessKind :: Read ,
1807+ "Deno.FsFile.prototype.stat()" ,
1808+ ) ?;
1809+ }
17961810 let stat = file. stat_async ( ) . await ?;
17971811 Ok ( stat. into ( ) )
17981812}
0 commit comments