From 641ccd58c168a296f5c36a191660ef63a32a98b9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 12 Dec 2019 14:48:47 -0800 Subject: [PATCH] Fix signature of `__wasilibc_find_relpath` Looks like this function changed upstream, so it needs to be adjusted for when used by libstd. --- src/libstd/sys/wasi/fs.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/libstd/sys/wasi/fs.rs b/src/libstd/sys/wasi/fs.rs index fad092e35c3e6..04bfdf67e12d2 100644 --- a/src/libstd/sys/wasi/fs.rs +++ b/src/libstd/sys/wasi/fs.rs @@ -364,7 +364,7 @@ impl OpenOptions { impl File { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { - let (dir, file) = open_parent(path, wasi::RIGHTS_PATH_OPEN)?; + let (dir, file) = open_parent(path)?; open_at(&dir, &file, opts) } @@ -452,7 +452,7 @@ impl DirBuilder { } pub fn mkdir(&self, p: &Path) -> io::Result<()> { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_CREATE_DIRECTORY)?; + let (dir, file) = open_parent(p)?; dir.create_directory(osstr2str(file.as_ref())?) } } @@ -478,13 +478,13 @@ pub fn readdir(p: &Path) -> io::Result { } pub fn unlink(p: &Path) -> io::Result<()> { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_UNLINK_FILE)?; + let (dir, file) = open_parent(p)?; dir.unlink_file(osstr2str(file.as_ref())?) } pub fn rename(old: &Path, new: &Path) -> io::Result<()> { - let (old, old_file) = open_parent(old, wasi::RIGHTS_PATH_RENAME_SOURCE)?; - let (new, new_file) = open_parent(new, wasi::RIGHTS_PATH_RENAME_TARGET)?; + let (old, old_file) = open_parent(old)?; + let (new, new_file) = open_parent(new)?; old.rename(osstr2str(old_file.as_ref())?, &new, osstr2str(new_file.as_ref())?) } @@ -495,12 +495,12 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> { } pub fn rmdir(p: &Path) -> io::Result<()> { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_REMOVE_DIRECTORY)?; + let (dir, file) = open_parent(p)?; dir.remove_directory(osstr2str(file.as_ref())?) } pub fn readlink(p: &Path) -> io::Result { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_READLINK)?; + let (dir, file) = open_parent(p)?; read_link(&dir, &file) } @@ -536,13 +536,13 @@ fn read_link(fd: &WasiFd, file: &Path) -> io::Result { } pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { - let (dst, dst_file) = open_parent(dst, wasi::RIGHTS_PATH_SYMLINK)?; + let (dst, dst_file) = open_parent(dst)?; dst.symlink(osstr2str(src.as_ref())?, osstr2str(dst_file.as_ref())?) } pub fn link(src: &Path, dst: &Path) -> io::Result<()> { - let (src, src_file) = open_parent(src, wasi::RIGHTS_PATH_LINK_SOURCE)?; - let (dst, dst_file) = open_parent(dst, wasi::RIGHTS_PATH_LINK_TARGET)?; + let (src, src_file) = open_parent(src)?; + let (dst, dst_file) = open_parent(dst)?; src.link( wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, osstr2str(src_file.as_ref())?, @@ -552,12 +552,12 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> { } pub fn stat(p: &Path) -> io::Result { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_FILESTAT_GET)?; + let (dir, file) = open_parent(p)?; metadata_at(&dir, wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, &file) } pub fn lstat(p: &Path) -> io::Result { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_FILESTAT_GET)?; + let (dir, file) = open_parent(p)?; metadata_at(&dir, 0, &file) } @@ -611,11 +611,11 @@ fn open_at(fd: &WasiFd, path: &Path, opts: &OpenOptions) -> io::Result { /// /// Note that this can fail if `p` doesn't look like it can be opened relative /// to any preopened file descriptor. -fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop, PathBuf)> { +fn open_parent(p: &Path) -> io::Result<(ManuallyDrop, PathBuf)> { let p = CString::new(p.as_os_str().as_bytes())?; unsafe { let mut ret = ptr::null(); - let fd = libc::__wasilibc_find_relpath(p.as_ptr(), rights, 0, &mut ret); + let fd = __wasilibc_find_relpath(p.as_ptr(), &mut ret); if fd == -1 { let msg = format!( "failed to find a preopened file descriptor \ @@ -635,6 +635,13 @@ fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop libc::c_int; + } } pub fn osstr2str(f: &OsStr) -> io::Result<&str> {