Fix a problem of converting os_str and raw bytes in the icecap backend.
@@ -20,12 +20,15 @@ use std::{
collections::HashMap,
convert::{AsRef, TryFrom},
ffi::OsString,
- os::unix::ffi::{OsStrExt, OsStringExt},
+ // TODO: wait for icecap support direct conversion bwtween bytes and os_str, bypassing
+ // potential utf-8 encoding check
path::{Component, Path, PathBuf},
string::String,
sync::{Arc, Mutex, MutexGuard},
vec::Vec,
};
+#[cfg(not(features = "icecap"))]
+use std::os::unix::ffi::{OsStrExt, OsStringExt};
use wasi_types::{
Advice, DirCookie, DirEnt, ErrNo, Event, Fd, FdFlags, FdStat, FileDelta, FileSize, FileStat,
FileType, Inode, LookupFlags, OpenFlags, PreopenType, Prestat, RiFlags, Rights, RoFlags,
@@ -312,6 +315,11 @@ impl InodeImpl {
.iter()
.enumerate()
{
+ // TODO: wait for icecap support direct conversion from os_str to bytes, bypassing
+ // potential utf-8 encoding check when calling to_str
+ #[cfg(features = "icecap")]
+ let path_byte = path.as_os_str().to_str().unwrap().as_bytes().to_vec();
+ #[cfg(not(features = "icecap"))]
let path_byte = path.as_os_str().as_bytes().to_vec();
let dir_ent = DirEnt {
next: (try_from_or_errno::<usize, u64>(index)? + 1u64).into(),
@@ -1617,6 +1625,12 @@ impl FileSystem {
inode_table.get(&inode)?.read_dir(&inode_table)?
};
for (_, sub_relative_path) in all_dir.iter() {
+ // TODO: wait for icecap support direct conversion from bytes to os_str, bypassing
+ // potential utf-8 encoding check
+ #[cfg(features = "icecap")]
+ let sub_relative_path =
+ PathBuf::from(String::from_utf8(sub_relative_path.to_vec()).unwrap());
+ #[cfg(not(features = "icecap"))]
let sub_relative_path =
PathBuf::from(OsString::from_vec(sub_relative_path.to_vec()));
// Ignore the path for current and parent directories.
