@@ -1772,13 +1772,20 @@ pub async fn op_fs_file_sync_async(
1772
1772
}
1773
1773
1774
1774
#[ op2( fast) ]
1775
- pub fn op_fs_file_stat_sync (
1775
+ pub fn op_fs_file_stat_sync < P : FsPermissions + ' static > (
1776
1776
state : & mut OpState ,
1777
1777
#[ smi] rid : ResourceId ,
1778
1778
#[ buffer] stat_out_buf : & mut [ u32 ] ,
1779
1779
) -> Result < ( ) , FsOpsError > {
1780
1780
let file =
1781
1781
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
+ }
1782
1789
let stat = file. stat_sync ( ) ?;
1783
1790
let serializable_stat = SerializableStat :: from ( stat) ;
1784
1791
serializable_stat. write ( stat_out_buf) ;
@@ -1787,12 +1794,19 @@ pub fn op_fs_file_stat_sync(
1787
1794
1788
1795
#[ op2( async ) ]
1789
1796
#[ serde]
1790
- pub async fn op_fs_file_stat_async (
1797
+ pub async fn op_fs_file_stat_async < P : FsPermissions + ' static > (
1791
1798
state : Rc < RefCell < OpState > > ,
1792
1799
#[ smi] rid : ResourceId ,
1793
1800
) -> Result < SerializableStat , FsOpsError > {
1794
1801
let file = FileResource :: get_file ( & state. borrow ( ) , rid)
1795
1802
. 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
+ }
1796
1810
let stat = file. stat_async ( ) . await ?;
1797
1811
Ok ( stat. into ( ) )
1798
1812
}
0 commit comments