Skip to content

Commit 70a2044

Browse files
committed
Fix fs_utf8 support for WASI.
1 parent 8d06b01 commit 70a2044

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

cap-std/src/fs_utf8/dir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Dir {
110110
/// builder.
111111
///
112112
/// This corresponds to [`std::fs::DirBuilder::create`].
113+
#[cfg(not(target_os = "wasi"))]
113114
#[inline]
114115
pub fn create_dir_with<P: AsRef<Utf8Path>>(
115116
&self,
@@ -308,6 +309,7 @@ impl Dir {
308309
/// paths relative to `self`. Also, on some platforms, this function
309310
/// may fail if the file or directory cannot be opened for reading or
310311
/// writing first.
312+
#[cfg(not(target_os = "wasi"))]
311313
pub fn set_permissions<P: AsRef<Utf8Path>>(
312314
&self,
313315
path: P,

cap-std/src/fs_utf8/file.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,23 @@ impl std::os::unix::fs::FileExt for File {
462462
#[cfg(target_os = "wasi")]
463463
impl std::os::wasi::fs::FileExt for File {
464464
#[inline]
465-
fn read_at(&self, bufs: &mut [IoSliceMut], offset: u64) -> io::Result<usize> {
466-
self.cap_std.read_at(bufs, offset)
465+
fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
466+
self.cap_std.read_at(buf, offset)
467+
}
468+
469+
#[inline]
470+
fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
471+
self.cap_std.write_at(buf, offset)
472+
}
473+
474+
#[inline]
475+
fn read_vectored_at(&self, bufs: &mut [IoSliceMut], offset: u64) -> io::Result<usize> {
476+
self.cap_std.read_vectored_at(bufs, offset)
467477
}
468478

469479
#[inline]
470-
fn write_at(&self, bufs: &[IoSlice], offset: u64) -> io::Result<usize> {
471-
self.cap_std.write_at(bufs, offset)
480+
fn write_vectored_at(&self, bufs: &[IoSlice], offset: u64) -> io::Result<usize> {
481+
self.cap_std.write_vectored_at(bufs, offset)
472482
}
473483

474484
#[inline]
@@ -501,45 +511,39 @@ impl std::os::wasi::fs::FileExt for File {
501511
}
502512

503513
#[inline]
504-
fn create_directory<P: AsRef<Utf8Path>>(
505-
&self,
506-
dir: P,
507-
) -> std::result::Result<(), std::io::Error> {
508-
let path = from_utf8(path)?;
509-
self.cap_std.create_directory(dir)
514+
fn create_directory<P: AsRef<Path>>(&self, path: P) -> std::result::Result<(), std::io::Error> {
515+
let path = path.as_ref();
516+
self.cap_std.create_directory(path)
510517
}
511518

512519
#[inline]
513-
fn read_link<P: AsRef<Utf8Path>>(
520+
fn read_link<P: AsRef<Path>>(
514521
&self,
515522
path: P,
516523
) -> std::result::Result<std::path::PathBuf, std::io::Error> {
517-
let path = from_utf8(path)?;
524+
let path = path.as_ref();
518525
self.cap_std.read_link(path)
519526
}
520527

521528
#[inline]
522-
fn metadata_at<P: AsRef<Utf8Path>>(
529+
fn metadata_at<P: AsRef<Path>>(
523530
&self,
524531
lookup_flags: u32,
525532
path: P,
526533
) -> std::result::Result<std::fs::Metadata, std::io::Error> {
527-
let path = from_utf8(path)?;
534+
let path = path.as_ref();
528535
self.cap_std.metadata_at(lookup_flags, path)
529536
}
530537

531538
#[inline]
532-
fn remove_file<P: AsRef<Utf8Path>>(&self, path: P) -> std::result::Result<(), std::io::Error> {
533-
let path = from_utf8(path)?;
539+
fn remove_file<P: AsRef<Path>>(&self, path: P) -> std::result::Result<(), std::io::Error> {
540+
let path = path.as_ref();
534541
self.cap_std.remove_file(path)
535542
}
536543

537544
#[inline]
538-
fn remove_directory<P: AsRef<Utf8Path>>(
539-
&self,
540-
path: P,
541-
) -> std::result::Result<(), std::io::Error> {
542-
let path = from_utf8(path)?;
545+
fn remove_directory<P: AsRef<Path>>(&self, path: P) -> std::result::Result<(), std::io::Error> {
546+
let path = path.as_ref();
543547
self.cap_std.remove_directory(path)
544548
}
545549
}

0 commit comments

Comments
 (0)