@@ -364,7 +364,7 @@ impl OpenOptions {
364
364
365
365
impl File {
366
366
pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
367
- let ( dir, file) = open_parent ( path, wasi :: RIGHTS_PATH_OPEN ) ?;
367
+ let ( dir, file) = open_parent ( path) ?;
368
368
open_at ( & dir, & file, opts)
369
369
}
370
370
@@ -452,7 +452,7 @@ impl DirBuilder {
452
452
}
453
453
454
454
pub fn mkdir ( & self , p : & Path ) -> io:: Result < ( ) > {
455
- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_CREATE_DIRECTORY ) ?;
455
+ let ( dir, file) = open_parent ( p) ?;
456
456
dir. create_directory ( osstr2str ( file. as_ref ( ) ) ?)
457
457
}
458
458
}
@@ -478,13 +478,13 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
478
478
}
479
479
480
480
pub fn unlink ( p : & Path ) -> io:: Result < ( ) > {
481
- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_UNLINK_FILE ) ?;
481
+ let ( dir, file) = open_parent ( p) ?;
482
482
dir. unlink_file ( osstr2str ( file. as_ref ( ) ) ?)
483
483
}
484
484
485
485
pub fn rename ( old : & Path , new : & Path ) -> io:: Result < ( ) > {
486
- let ( old, old_file) = open_parent ( old, wasi :: RIGHTS_PATH_RENAME_SOURCE ) ?;
487
- let ( new, new_file) = open_parent ( new, wasi :: RIGHTS_PATH_RENAME_TARGET ) ?;
486
+ let ( old, old_file) = open_parent ( old) ?;
487
+ let ( new, new_file) = open_parent ( new) ?;
488
488
old. rename ( osstr2str ( old_file. as_ref ( ) ) ?, & new, osstr2str ( new_file. as_ref ( ) ) ?)
489
489
}
490
490
@@ -495,12 +495,12 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
495
495
}
496
496
497
497
pub fn rmdir ( p : & Path ) -> io:: Result < ( ) > {
498
- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_REMOVE_DIRECTORY ) ?;
498
+ let ( dir, file) = open_parent ( p) ?;
499
499
dir. remove_directory ( osstr2str ( file. as_ref ( ) ) ?)
500
500
}
501
501
502
502
pub fn readlink ( p : & Path ) -> io:: Result < PathBuf > {
503
- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_READLINK ) ?;
503
+ let ( dir, file) = open_parent ( p) ?;
504
504
read_link ( & dir, & file)
505
505
}
506
506
@@ -536,13 +536,13 @@ fn read_link(fd: &WasiFd, file: &Path) -> io::Result<PathBuf> {
536
536
}
537
537
538
538
pub fn symlink ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
539
- let ( dst, dst_file) = open_parent ( dst, wasi :: RIGHTS_PATH_SYMLINK ) ?;
539
+ let ( dst, dst_file) = open_parent ( dst) ?;
540
540
dst. symlink ( osstr2str ( src. as_ref ( ) ) ?, osstr2str ( dst_file. as_ref ( ) ) ?)
541
541
}
542
542
543
543
pub fn link ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
544
- let ( src, src_file) = open_parent ( src, wasi :: RIGHTS_PATH_LINK_SOURCE ) ?;
545
- let ( dst, dst_file) = open_parent ( dst, wasi :: RIGHTS_PATH_LINK_TARGET ) ?;
544
+ let ( src, src_file) = open_parent ( src) ?;
545
+ let ( dst, dst_file) = open_parent ( dst) ?;
546
546
src. link (
547
547
wasi:: LOOKUPFLAGS_SYMLINK_FOLLOW ,
548
548
osstr2str ( src_file. as_ref ( ) ) ?,
@@ -552,12 +552,12 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
552
552
}
553
553
554
554
pub fn stat ( p : & Path ) -> io:: Result < FileAttr > {
555
- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_FILESTAT_GET ) ?;
555
+ let ( dir, file) = open_parent ( p) ?;
556
556
metadata_at ( & dir, wasi:: LOOKUPFLAGS_SYMLINK_FOLLOW , & file)
557
557
}
558
558
559
559
pub fn lstat ( p : & Path ) -> io:: Result < FileAttr > {
560
- let ( dir, file) = open_parent ( p, wasi :: RIGHTS_PATH_FILESTAT_GET ) ?;
560
+ let ( dir, file) = open_parent ( p) ?;
561
561
metadata_at ( & dir, 0 , & file)
562
562
}
563
563
@@ -611,11 +611,11 @@ fn open_at(fd: &WasiFd, path: &Path, opts: &OpenOptions) -> io::Result<File> {
611
611
///
612
612
/// Note that this can fail if `p` doesn't look like it can be opened relative
613
613
/// to any preopened file descriptor.
614
- fn open_parent ( p : & Path , rights : wasi :: Rights ) -> io:: Result < ( ManuallyDrop < WasiFd > , PathBuf ) > {
614
+ fn open_parent ( p : & Path ) -> io:: Result < ( ManuallyDrop < WasiFd > , PathBuf ) > {
615
615
let p = CString :: new ( p. as_os_str ( ) . as_bytes ( ) ) ?;
616
616
unsafe {
617
617
let mut ret = ptr:: null ( ) ;
618
- let fd = libc :: __wasilibc_find_relpath ( p. as_ptr ( ) , rights , 0 , & mut ret) ;
618
+ let fd = __wasilibc_find_relpath ( p. as_ptr ( ) , & mut ret) ;
619
619
if fd == -1 {
620
620
let msg = format ! (
621
621
"failed to find a preopened file descriptor \
@@ -635,6 +635,13 @@ fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop<WasiF
635
635
636
636
return Ok ( ( ManuallyDrop :: new ( WasiFd :: from_raw ( fd as u32 ) ) , path) ) ;
637
637
}
638
+
639
+ extern "C" {
640
+ pub fn __wasilibc_find_relpath (
641
+ path : * const libc:: c_char ,
642
+ relative_path : * mut * const libc:: c_char ,
643
+ ) -> libc:: c_int ;
644
+ }
638
645
}
639
646
640
647
pub fn osstr2str ( f : & OsStr ) -> io:: Result < & str > {
0 commit comments