@@ -339,7 +339,8 @@ impl DirBuilder {
339
339
}
340
340
341
341
pub fn mkdir ( & self , p : & Path ) -> io:: Result < ( ) > {
342
- cvt ( libc:: mkdir ( p. to_str ( ) . unwrap ( ) , self . mode ) ) ?;
342
+ let fd = cvt ( libc:: open ( p. to_str ( ) . unwrap ( ) , libc:: O_CREAT | libc:: O_DIRECTORY | libc:: O_EXCL | ( self . mode as usize & 0o777 ) ) ) ?;
343
+ let _ = libc:: close ( fd) ;
343
344
Ok ( ( ) )
344
345
}
345
346
@@ -372,11 +373,12 @@ impl fmt::Debug for File {
372
373
373
374
pub fn readdir ( p : & Path ) -> io:: Result < ReadDir > {
374
375
let root = Arc :: new ( p. to_path_buf ( ) ) ;
375
- let mut options = OpenOptions :: new ( ) ;
376
- options . read ( true ) ;
377
- let fd = File :: open ( p , & options ) ? ;
376
+
377
+ let fd = cvt ( open ( p . to_str ( ) . unwrap ( ) , libc :: O_CLOEXEC | libc :: O_RDONLY | libc :: O_DIRECTORY ) ) ? ;
378
+ let file = FileDesc :: new ( fd ) ;
378
379
let mut data = Vec :: new ( ) ;
379
- fd. read_to_end ( & mut data) ?;
380
+ file. read_to_end ( & mut data) ?;
381
+
380
382
Ok ( ReadDir { data : data, i : 0 , root : root } )
381
383
}
382
384
@@ -437,10 +439,11 @@ pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
437
439
438
440
pub fn stat ( p : & Path ) -> io:: Result < FileAttr > {
439
441
let mut stat: stat = stat:: default ( ) ;
440
- let mut options = OpenOptions :: new ( ) ;
441
- options. read ( true ) ;
442
- let file = File :: open ( p, & options) ?;
443
- cvt ( fstat ( file. 0 . raw ( ) , & mut stat) ) ?;
442
+
443
+ let fd = cvt ( open ( p. to_str ( ) . unwrap ( ) , libc:: O_CLOEXEC | libc:: O_STAT ) ) ?;
444
+ cvt ( fstat ( fd, & mut stat) ) ?;
445
+ let _ = libc:: close ( fd) ;
446
+
444
447
Ok ( FileAttr { stat : stat } )
445
448
}
446
449
0 commit comments