incorporate dan's suggestions on readdir
This commit is contained in:
@@ -286,31 +286,27 @@ impl WasiDir for cap_std::fs::Dir {
|
|||||||
use cap_fs_ext::MetadataExt;
|
use cap_fs_ext::MetadataExt;
|
||||||
|
|
||||||
// cap_std's read_dir does not include . and .., we should prepend these.
|
// cap_std's read_dir does not include . and .., we should prepend these.
|
||||||
// Why closures? failure of any individual entry doesn't mean the whole method should
|
// Why does the Ok contain a tuple? We can't construct a cap_std::fs::DirEntry, and we don't
|
||||||
// fail.
|
|
||||||
// Why is the Ok case a tuple? We can't construct a cap_std::fs::DirEntry, and we don't
|
|
||||||
// have enough info to make a ReaddirEntity yet.
|
// have enough info to make a ReaddirEntity yet.
|
||||||
|
let dir_meta = self.dir_metadata()?;
|
||||||
let rd = vec![
|
let rd = vec![
|
||||||
(|| {
|
{
|
||||||
let meta = self.dir_metadata()?;
|
|
||||||
let name = ".".to_owned();
|
let name = ".".to_owned();
|
||||||
let namelen = name.as_bytes().len().try_into()?;
|
let namelen = name.as_bytes().len().try_into().expect("1 wont overflow");
|
||||||
Ok((FileType::Directory, meta.ino(), namelen, name))
|
Ok((FileType::Directory, dir_meta.ino(), namelen, name))
|
||||||
})(),
|
},
|
||||||
(|| {
|
{
|
||||||
// XXX if parent dir is mounted it *might* be possible to give its inode, but we
|
// XXX if parent dir is mounted it *might* be possible to give its inode, but we
|
||||||
// don't know that in this context.
|
// don't know that in this context.
|
||||||
let name = "..".to_owned();
|
let name = "..".to_owned();
|
||||||
let namelen = name.as_bytes().len().try_into()?;
|
let namelen = name.as_bytes().len().try_into().expect("2 wont overflow");
|
||||||
Ok((FileType::Directory, 0, namelen, name))
|
Ok((FileType::Directory, dir_meta.ino(), namelen, name))
|
||||||
})(),
|
},
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(
|
.chain(
|
||||||
// Now process the `DirEntry`s:
|
// Now process the `DirEntry`s:
|
||||||
self.read_dir(Path::new("."))
|
self.entries()?.map(|entry| {
|
||||||
.expect("always possible to readdir an open Dir") // XXX is this true?
|
|
||||||
.map(|entry| {
|
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let meta = entry.metadata()?;
|
let meta = entry.metadata()?;
|
||||||
let inode = meta.ino();
|
let inode = meta.ino();
|
||||||
|
|||||||
Reference in New Issue
Block a user