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
67 changes: 0 additions & 67 deletions crates/wasi/src/filesystem/primitives/dir_entry.rs

This file was deleted.

15 changes: 0 additions & 15 deletions crates/wasi/src/filesystem/primitives/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ impl Metadata {
Ok(Self::from_parts(std, ext, file_type))
}

/// Constructs a new instance of `Self` from the given
/// [`std::fs::Metadata`].
///
/// As with the comments in [`std::fs::Metadata::volume_serial_number`] and
/// nearby functions, some fields of the resulting metadata will be `None`.
///
/// [`std::fs::Metadata::volume_serial_number`]: https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html#tymethod.volume_serial_number
#[cfg(windows)]
#[inline]
pub fn from_just_metadata(std: fs::Metadata) -> Self {
let ext = ImplMetadataExt::from_just_metadata(&std);
let file_type = ImplFileTypeExt::from_just_metadata(&std);
Self::from_parts(std, ext, file_type)
}

#[inline]
fn from_parts(std: fs::Metadata, ext: ImplMetadataExt, file_type: FileType) -> Self {
Self {
Expand Down
17 changes: 1 addition & 16 deletions crates/wasi/src/filesystem/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
use std::path::{Component, Path, PathBuf};
use std::{fs, io};

mod dir_entry;
mod file_type;
mod maybe_owned_file;
mod metadata;
mod open_options;
mod open_parent;
mod open_unchecked_error;
mod read_dir;

mod errors;
mod manually;
Expand All @@ -51,16 +49,15 @@ use open_parent::open_parent;
use open_unchecked_error::*;
use sys::*;

pub(crate) use dir_entry::DirEntry;
pub(crate) use file_type::FileType;
#[cfg(any(unix, target_os = "vxworks"))]
pub(crate) use file_type::FileTypeExt;
#[cfg(windows)]
pub(crate) use metadata::_WindowsByHandle;
pub(crate) use metadata::{Metadata, MetadataExt};
pub(crate) use open_options::*;
pub(crate) use read_dir::read_base_dir;
pub(crate) use sys::open_ambient_dir;
pub(crate) use sys::read_dir;
pub(crate) use sys::set_times;
pub(crate) use sys::set_times_nofollow;

Expand Down Expand Up @@ -285,18 +282,6 @@ fn open_dir_unchecked(start: &fs::File, path: &Path) -> io::Result<fs::File> {
open_unchecked(start, path, &dir_options()).map_err(Into::into)
}

/// Like `open_dir_unchecked`, but additionally request the ability to read the
/// directory entries.
#[inline]
#[allow(dead_code)]
fn open_dir_for_reading_unchecked(
start: &fs::File,
path: &Path,
follow: FollowSymlinks,
) -> io::Result<fs::File> {
open_unchecked(start, path, readdir_options().follow(follow)).map_err(Into::into)
}

pub(crate) fn remove_file(start: &fs::File, path: &Path) -> io::Result<()> {
#[cfg(target_os = "freebsd")]
if sys::remove_file_fast(start, path)? {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasi/src/filesystem/primitives/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct OpenOptions {
pub(crate) rsync: bool,
#[cfg(not(windows))]
pub(crate) nonblock: bool,
#[cfg(not(windows))]
pub(crate) readdir_required: bool,
pub(crate) follow: FollowSymlinks,

Expand Down Expand Up @@ -80,6 +81,7 @@ impl OpenOptions {
rsync: false,
#[cfg(not(windows))]
nonblock: false,
#[cfg(not(windows))]
readdir_required: false,
follow: FollowSymlinks::Yes,

Expand Down Expand Up @@ -150,6 +152,7 @@ impl OpenOptions {

/// Sets the option to request the ability to read directory entries.
#[inline]
#[cfg(not(windows))]
pub(crate) fn readdir_required(&mut self, readdir_required: bool) -> &mut Self {
self.readdir_required = readdir_required;
self
Expand Down
38 changes: 0 additions & 38 deletions crates/wasi/src/filesystem/primitives/read_dir.rs

This file was deleted.

29 changes: 9 additions & 20 deletions crates/wasi/src/filesystem/primitives/tests/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ fn dir_entry_methods() {
h::create_dir_all(&start, "a").unwrap();
h::create(&start, "b").unwrap();

// `DirEntry::file_type` is gone; the metadata checks still cover this.
for file in h::read_dir(&start, ".").unwrap().map(|f| f.unwrap()) {
let fname = file.file_name();
for (fname, ty) in p::read_dir(&start).unwrap().map(|f| f.unwrap()) {
match fname.to_str() {
Some("a") => {
assert!(file.metadata().unwrap().is_dir());
assert!(ty.is_dir());
}
Some("b") => {
assert!(file.metadata().unwrap().file_type().is_file());
assert!(ty.is_file());
}
f => panic!("unknown file name: {f:?}"),
}
Expand Down Expand Up @@ -600,10 +598,13 @@ fn file_test_directoryinfo_readdir() {
let msg = msg_str.as_bytes();
check!(w.write(msg));
}
let files = check!(h::read_dir(&start, dir));
let files = {
let dir_handle = check!(p::open_dir(&start, dir.as_ref()));
check!(p::read_dir(&dir_handle))
};
let mut mem = [0; 4];
for f in files {
let f = f.unwrap().file_name();
let (f, _ty) = f.unwrap();
{
check!(check!(h::open(&start, &f)).read(&mut mem));
let read_str = str::from_utf8(&mem).unwrap();
Expand Down Expand Up @@ -1027,23 +1028,11 @@ fn mkdir_trailing_slash() {
check!(h::create_dir_all(&start, &path.join("a/")));
}

#[test]
fn dir_entry_debug() {
let tmpdir = tmpdir();
let start = h::dir_of(&tmpdir);
h::create(&start, "b").unwrap();
let mut read_dir = h::read_dir(&start, ".").unwrap();
let dir_entry = read_dir.next().unwrap().unwrap();
let actual = format!("{dir_entry:?}");
let expected = format!("DirEntry({:?})", dir_entry.file_name());
assert_eq!(actual, expected);
}

#[test]
fn read_dir_not_found() {
let tmpdir = tmpdir();
let start = h::dir_of(&tmpdir);
let res = h::read_dir(&start, "path/that/does/not/exist");
let res = p::open_dir(&start, "path/that/does/not/exist".as_ref());
assert_eq!(res.err().unwrap().kind(), ErrorKind::NotFound);
}

Expand Down
49 changes: 24 additions & 25 deletions crates/wasi/src/filesystem/primitives/tests/fs_additional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ fn dotdot_at_end_of_symlink() {

check!(h::metadata(&start, path));

let contents = check!(h::read_dir(&start, path));
let dir_handle = check!(p::open_dir(&start, path.as_ref()));
let contents = check!(p::read_dir(&dir_handle));
for entry in contents {
let _entry = check!(entry);
}
Expand All @@ -149,7 +150,8 @@ fn dotdot_at_end_of_symlink_all_inside_dir() {

check!(h::metadata(&start, path));

let contents = check!(h::read_dir(&start, path));
let dir_handle = check!(p::open_dir(&start, path.as_ref()));
let contents = check!(p::read_dir(&dir_handle));
for entry in contents {
let _entry = check!(entry);
}
Expand All @@ -174,7 +176,8 @@ fn dotdot_slashdot_at_end_of_symlink() {

check!(h::metadata(&start, path));

let contents = check!(h::read_dir(&start, path));
let dir_handle = check!(p::open_dir(&start, path.as_ref()));
let contents = check!(p::read_dir(&dir_handle));
for entry in contents {
let _entry = check!(entry);
}
Expand All @@ -200,7 +203,8 @@ fn dotdot_slashdot_at_end_of_symlink_all_inside_dir() {

check!(h::metadata(&start, path));

let contents = check!(h::read_dir(&start, path));
let dir_handle = check!(p::open_dir(&start, path.as_ref()));
let contents = check!(p::read_dir(&dir_handle));
for entry in contents {
let _entry = check!(entry);
}
Expand Down Expand Up @@ -454,17 +458,17 @@ fn file_test_directoryinfo_readdir() {
check!(w.write(msg));
}
let sub = check!(p::open_dir(&start, Path::new(dir)));
let files = check!(p::read_base_dir(&sub));
let files = check!(p::read_dir(&sub));
let mut mem = [0; 4];
for f in files {
let f = f.unwrap();
let (f, _ty) = f.unwrap();
{
check!(check!(h::open(&sub, f.file_name())).read(&mut mem));
check!(check!(h::open(&sub, &f)).read(&mut mem));
let read_str = str::from_utf8(&mem).unwrap();
let expected = format!("{}{}", prefix, f.file_name().to_str().unwrap());
let expected = format!("{}{}", prefix, f.to_str().unwrap());
assert_eq!(expected, read_str);
}
check!(p::remove_file(&sub, Path::new(&f.file_name())));
check!(p::remove_file(&sub, Path::new(&f)));
}
drop(sub);
check!(p::remove_dir(&start, Path::new(dir)));
Expand Down Expand Up @@ -895,9 +899,12 @@ fn readdir_with_trailing_slashdot() {
check!(h::create(&start, "dir/green"));
check!(h::create(&start, "dir/blue"));

assert_eq!(check!(h::read_dir(&start, "dir")).count(), 3);
assert_eq!(check!(h::read_dir(&start, "dir/")).count(), 3);
assert_eq!(check!(h::read_dir(&start, "dir/.")).count(), 3);
let h1 = check!(p::open_dir(&start, "dir".as_ref()));
let h2 = check!(p::open_dir(&start, "dir/".as_ref()));
let h3 = check!(p::open_dir(&start, "dir/.".as_ref()));
assert_eq!(check!(p::read_dir(&h1)).count(), 3);
assert_eq!(check!(p::read_dir(&h2)).count(), 3);
assert_eq!(check!(p::read_dir(&h3)).count(), 3);
}

#[test]
Expand All @@ -910,13 +917,12 @@ fn metadata_vs_std_fs() {

let cap_std_dir = check!(p::Metadata::from_file(&dir));
let cap_std_file = check!(p::Metadata::from_file(&file));
let cap_std_dir_entry = {
let mut entries = check!(p::read_base_dir(&dir));
let entry = check!(entries.next().unwrap());
assert_eq!(entry.file_name(), "file");
{
let mut entries = check!(p::read_dir(&dir));
let (entry, _ty) = check!(entries.next().unwrap());
assert_eq!(entry, "file");
assert!(entries.next().is_none(), "unexpected dir entry");
check!(entry.metadata())
};
}

let std_dir = check!(dir.metadata());
let std_file = check!(file.metadata());
Expand All @@ -928,7 +934,6 @@ fn metadata_vs_std_fs() {

check_metadata(&std_dir, &cap_std_dir);
check_metadata(&std_file, &cap_std_file);
check_metadata(&std_file, &cap_std_dir_entry);
}

fn check_metadata(std: &std::fs::Metadata, cap: &p::Metadata) {
Expand Down Expand Up @@ -1278,12 +1283,9 @@ fn trailing_slash_symlink() {

for path in ["hidden", "hidden/", "indirect", "indirect/"] {
let open_dir = p::open_dir(&sandbox, Path::new(path));
let read_dir = h::read_dir(&sandbox, path);
assert!(open_dir.is_err());
assert!(read_dir.is_err());
if cfg!(unix) {
error_contains!(open_dir, "a path led outside of the filesystem");
error_contains!(read_dir, "a path led outside of the filesystem");
}
}
}
Expand Down Expand Up @@ -1343,12 +1345,9 @@ fn trailing_slash_symlink_more() {
"root_link/",
] {
let open_dir = p::open_dir(&sandbox, Path::new(path));
let read_dir = h::read_dir(&sandbox, path);
assert!(open_dir.is_err());
assert!(read_dir.is_err());
if cfg!(unix) {
error_contains!(open_dir, "a path led outside of the filesystem");
error_contains!(read_dir, "a path led outside of the filesystem");
}
}
}
Loading
Loading