Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions cap-async-std/src/fs_utf8/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn open<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<File> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.open(path).await.map(File::from_cap_std)
}

Expand All @@ -76,7 +76,7 @@ impl Dir {
path: P,
options: &OpenOptions,
) -> io::Result<File> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std
.open_with(path, options)
.await
Expand All @@ -86,7 +86,7 @@ impl Dir {
/// Attempts to open a directory.
#[inline]
pub async fn open_dir<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Self> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.open_dir(path).await.map(Self::from_cap_std)
}

Expand All @@ -98,7 +98,7 @@ impl Dir {
/// TODO: async: fix this when we fix https://github.com/bytecodealliance/cap-std/issues/51
#[inline]
pub fn create_dir<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.create_dir(path)
}

Expand All @@ -111,7 +111,7 @@ impl Dir {
/// TODO: async: fix this when we fix https://github.com/bytecodealliance/cap-std/issues/51
#[inline]
pub fn create_dir_all<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.create_dir_all(path)
}

Expand All @@ -127,7 +127,7 @@ impl Dir {
path: P,
dir_builder: &DirBuilder,
) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.create_dir_with(path, dir_builder)
}

Expand All @@ -137,7 +137,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn create<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<File> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.create(path).await.map(File::from_cap_std)
}

Expand All @@ -149,7 +149,7 @@ impl Dir {
/// directory represented by `self`.
#[inline]
pub async fn canonicalize<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Utf8PathBuf> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.canonicalize(path).await.and_then(to_utf8)
}

Expand Down Expand Up @@ -194,7 +194,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn metadata<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Metadata> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.metadata(path).await
}

Expand All @@ -210,7 +210,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn read_dir<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<ReadDir> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.read_dir(path).await.map(ReadDir::from_cap_std)
}

Expand All @@ -220,7 +220,7 @@ impl Dir {
/// relative to `self`.
#[inline]
pub async fn read<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Vec<u8>> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.read(path).await
}

Expand All @@ -230,7 +230,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn read_link<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Utf8PathBuf> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.read_link(path).await.and_then(to_utf8)
}

Expand All @@ -240,7 +240,7 @@ impl Dir {
/// accesses paths relative to `self`.
#[inline]
pub async fn read_to_string<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<String> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.read_to_string(path).await
}

Expand All @@ -250,7 +250,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn remove_dir<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.remove_dir(path).await
}

Expand All @@ -261,7 +261,7 @@ impl Dir {
/// accesses paths relative to `self`.
#[inline]
pub async fn remove_dir_all<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.remove_dir_all(path).await
}

Expand Down Expand Up @@ -292,7 +292,7 @@ impl Dir {
/// paths relative to `self`.
#[inline]
pub async fn remove_file<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.remove_file(path).await
}

Expand Down Expand Up @@ -324,7 +324,7 @@ impl Dir {
path: P,
perm: Permissions,
) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.set_permissions(path, perm).await
}

Expand All @@ -334,7 +334,7 @@ impl Dir {
/// accesses paths relative to `self`.
#[inline]
pub async fn symlink_metadata<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Metadata> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.symlink_metadata(path).await
}

Expand All @@ -348,7 +348,7 @@ impl Dir {
path: P,
contents: C,
) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.write(path, contents).await
}

Expand Down Expand Up @@ -450,7 +450,7 @@ impl Dir {
&self,
path: P,
) -> io::Result<UnixListener> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.bind_unix_listener(path).await
}

Expand All @@ -465,7 +465,7 @@ impl Dir {
#[cfg(unix)]
#[inline]
pub async fn connect_unix_stream<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<UnixStream> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.connect_unix_stream(path).await
}

Expand All @@ -483,7 +483,7 @@ impl Dir {
&self,
path: P,
) -> io::Result<UnixDatagram> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std.bind_unix_datagram(path).await
}

Expand All @@ -503,7 +503,7 @@ impl Dir {
unix_datagram: &UnixDatagram,
path: P,
) -> io::Result<()> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std
.connect_unix_datagram(unix_datagram, path)
.await
Expand All @@ -526,7 +526,7 @@ impl Dir {
buf: &[u8],
path: P,
) -> io::Result<usize> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
self.cap_std
.send_to_unix_datagram_addr(unix_datagram, buf, path)
.await
Expand All @@ -540,7 +540,7 @@ impl Dir {
/// accesses paths relative to `self`.
#[inline]
pub async fn exists<P: AsRef<Utf8Path>>(&self, path: P) -> bool {
match from_utf8(path) {
match from_utf8(path.as_ref()) {
Ok(path) => self.cap_std.exists(path).await,
Err(_) => false,
}
Expand All @@ -552,7 +552,7 @@ impl Dir {
/// accesses paths relative to `self`.
#[inline]
pub async fn try_exists<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<bool> {
self.cap_std.try_exists(from_utf8(path)?).await
self.cap_std.try_exists(from_utf8(path.as_ref())?).await
}

/// Returns `true` if the path exists on disk and is pointing at a regular
Expand All @@ -562,7 +562,7 @@ impl Dir {
/// accesses paths relative to `self`.
#[inline]
pub async fn is_file<P: AsRef<Utf8Path>>(&self, path: P) -> bool {
match from_utf8(path) {
match from_utf8(path.as_ref()) {
Ok(path) => self.cap_std.is_file(path).await,
Err(_) => false,
}
Expand All @@ -576,7 +576,7 @@ impl Dir {
/// of broken symbolic links, this will return `false`.
#[inline]
pub async fn is_dir<P: AsRef<Utf8Path>>(&self, path: P) -> bool {
match from_utf8(path) {
match from_utf8(path.as_ref()) {
Ok(path) => self.cap_std.is_dir(path).await,
Err(_) => false,
}
Expand All @@ -594,7 +594,7 @@ impl Dir {
path: P,
ambient_authority: AmbientAuthority,
) -> io::Result<Self> {
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
crate::fs::Dir::open_ambient_dir(path, ambient_authority)
.await
.map(Self::from_cap_std)
Expand Down Expand Up @@ -630,7 +630,7 @@ impl Dir {
ambient_authority: AmbientAuthority,
) -> io::Result<()> {
let _ = ambient_authority;
let path = from_utf8(path)?;
let path = from_utf8(path.as_ref())?;
fs::create_dir_all(path).await
}
}
Expand Down
39 changes: 19 additions & 20 deletions cap-async-std/src/fs_utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,31 @@ pub use camino;

use camino::{Utf8Path, Utf8PathBuf};

fn from_utf8<P: AsRef<Utf8Path>>(path: P) -> std::io::Result<async_std::path::PathBuf> {
#[cfg(not(feature = "arf_strings"))]
{
Ok(path.as_ref().as_std_path().to_path_buf().into())
}
#[cfg(not(feature = "arf_strings"))]
fn from_utf8<'a>(path: &'a Utf8Path) -> std::io::Result<&'a async_std::path::Path> {
Ok(path.as_std_path())
}

#[cfg(feature = "arf_strings")]
{
#[cfg(not(windows))]
let path = {
#[cfg(unix)]
use std::{ffi::OsString, os::unix::ffi::OsStringExt};
#[cfg(target_os = "wasi")]
use std::{ffi::OsString, os::wasi::ffi::OsStringExt};
#[cfg(feature = "arf_strings")]
fn from_utf8<'a>(path: &'a Utf8Path) -> std::io::Result<async_std::path::PathBuf> {
#[cfg(not(windows))]
let path = {
#[cfg(unix)]
use std::{ffi::OsString, os::unix::ffi::OsStringExt};
#[cfg(target_os = "wasi")]
use std::{ffi::OsString, os::wasi::ffi::OsStringExt};

let string = arf_strings::str_to_host(path.as_ref().as_str())?;
OsString::from_vec(string.into_bytes())
};
let string = arf_strings::str_to_host(path.as_str())?;
OsString::from_vec(string.into_bytes())
};

#[cfg(windows)]
let path = arf_strings::str_to_host(path.as_ref().as_str())?;
#[cfg(windows)]
let path = arf_strings::str_to_host(path.as_str())?;

Ok(path.into())
}
Ok(path.into())
}


fn to_utf8<P: AsRef<async_std::path::Path>>(path: P) -> std::io::Result<Utf8PathBuf> {
#[cfg(not(feature = "arf_strings"))]
#[cfg(not(windows))]
Expand Down
Loading