Skip to content

Commit

Permalink
Have cap-std re-export the new traits, and update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Jan 9, 2024
1 parent 44c8940 commit 22c65b8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions cap-async-std/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub use cap_primitives::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permis
// Re-export conditional types from `cap_primitives`.
#[cfg(any(unix, target_os = "vxworks", all(windows, windows_file_type_ext)))]
pub use cap_primitives::fs::FileTypeExt;
pub use cap_primitives::fs::{PermissionsExt, MetadataExt};

// Re-export things from `async_std` that we can use as-is.
#[cfg(target_os = "wasi")]
Expand Down
1 change: 1 addition & 0 deletions cap-async-std/src/fs_utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub use crate::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};
// Re-export conditional types from `cap_primitives`.
#[cfg(any(unix, target_os = "vxworks", all(windows, windows_file_type_ext)))]
pub use cap_primitives::fs::FileTypeExt;
pub use cap_primitives::fs::{PermissionsExt, MetadataExt};

// Re-export `camino` to make it easy for users to depend on the same
// version we do, because we use its types in our public API.
Expand Down
1 change: 1 addition & 0 deletions cap-std/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ pub use cap_primitives::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permis
// Re-export conditional types from `cap_primitives`.
#[cfg(any(unix, target_os = "vxworks", all(windows, windows_file_type_ext)))]
pub use cap_primitives::fs::FileTypeExt;
pub use cap_primitives::fs::{MetadataExt, PermissionsExt};
1 change: 1 addition & 0 deletions cap-std/src/fs_utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use crate::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};
// Re-export conditional types from `cap_primitives`.
#[cfg(any(unix, target_os = "vxworks", all(windows, windows_file_type_ext)))]
pub use cap_primitives::fs::FileTypeExt;
pub use cap_primitives::fs::{MetadataExt, PermissionsExt};

// Re-export `camino` to make it easy for users to depend on the same
// version we do, because we use its types in our public API.
Expand Down
1 change: 1 addition & 0 deletions cap-tempfile/src/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ mod test {
// Test that we created with the right permissions
#[cfg(any(target_os = "android", target_os = "linux"))]
{
use cap_std::fs_utf8::MetadataExt;
use rustix::fs::{MetadataExt, Mode};
let umask = get_process_umask()?;
let metadata = tf.as_file().metadata().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn file_test_io_read_write_at() {
#[cfg(unix)]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), ignore)]
fn set_get_unix_permissions() {
use std::os::unix::fs::PermissionsExt;
use cap_std::fs::PermissionsExt;

let tmpdir = tmpdir();
let filename = "set_get_unix_permissions";
Expand Down
39 changes: 21 additions & 18 deletions tests/fs_additional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,10 @@ fn check_metadata(std: &std::fs::Metadata, cap: &cap_std::fs::Metadata) {
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
assert_eq!(std.permissions().mode(), cap.permissions().mode());
assert_eq!(
std.permissions().mode(),
cap_std::fs::PermissionsExt::mode(&cap.permissions())
);
}

// If the standard library supports file modified/accessed/created times,
Expand Down Expand Up @@ -1022,28 +1025,28 @@ fn check_metadata(std: &std::fs::Metadata, cap: &cap_std::fs::Metadata) {
#[cfg(unix)]
{
use std::os::unix::fs::MetadataExt;
assert_eq!(std.dev(), cap.dev());
assert_eq!(std.ino(), cap.ino());
assert_eq!(std.mode(), cap.mode());
assert_eq!(std.nlink(), cap.nlink());
assert_eq!(std.uid(), cap.uid());
assert_eq!(std.gid(), cap.gid());
assert_eq!(std.rdev(), cap.rdev());
assert_eq!(std.size(), cap.size());
assert_eq!(std.dev(), cap_std::fs::MetadataExt::dev(cap));
assert_eq!(std.ino(), cap_std::fs::MetadataExt::ino(cap));
assert_eq!(std.mode(), cap_std::fs::MetadataExt::mode(cap));
assert_eq!(std.nlink(), cap_std::fs::MetadataExt::nlink(cap));
assert_eq!(std.uid(), cap_std::fs::MetadataExt::uid(cap));
assert_eq!(std.gid(), cap_std::fs::MetadataExt::gid(cap));
assert_eq!(std.rdev(), cap_std::fs::MetadataExt::rdev(cap));
assert_eq!(std.size(), cap_std::fs::MetadataExt::size(cap));
assert!(
((std.atime() - i64::from(ACCESS_TOLERANCE_SEC))
..(std.atime() + i64::from(ACCESS_TOLERANCE_SEC)))
.contains(&cap.atime()),
.contains(&cap_std::fs::MetadataExt::atime(cap)),
"std atime {}, cap atime {}",
std.atime(),
cap.atime()
cap_std::fs::MetadataExt::atime(cap)
);
assert!((0..1_000_000_000).contains(&cap.atime_nsec()));
assert_eq!(std.mtime(), cap.mtime());
assert_eq!(std.mtime_nsec(), cap.mtime_nsec());
assert_eq!(std.ctime(), cap.ctime());
assert_eq!(std.ctime_nsec(), cap.ctime_nsec());
assert_eq!(std.blksize(), cap.blksize());
assert_eq!(std.blocks(), cap.blocks());
assert!((0..1_000_000_000).contains(&cap_std::fs::MetadataExt::atime_nsec(cap)));
assert_eq!(std.mtime(), cap_std::fs::MetadataExt::mtime(cap));
assert_eq!(std.mtime_nsec(), cap_std::fs::MetadataExt::mtime_nsec(cap));
assert_eq!(std.ctime(), cap_std::fs::MetadataExt::ctime(cap));
assert_eq!(std.ctime_nsec(), cap_std::fs::MetadataExt::ctime_nsec(cap));
assert_eq!(std.blksize(), cap_std::fs::MetadataExt::blksize(cap));
assert_eq!(std.blocks(), cap_std::fs::MetadataExt::blocks(cap));
}
}
2 changes: 1 addition & 1 deletion tests/fs_utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fn file_test_io_read_write_at() {
#[cfg(unix)]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), ignore)]
fn set_get_unix_permissions() {
use std::os::unix::fs::PermissionsExt;
use cap_std::fs::PermissionsExt;

let tmpdir = tmpdir();
let filename = "set_get_unix_permissions";
Expand Down

0 comments on commit 22c65b8

Please sign in to comment.