split path_filestat test into two, improve variable names
This commit is contained in:
@@ -46,17 +46,17 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
|
||||
);
|
||||
|
||||
// Check file size
|
||||
let mut stat = wasi::path_filestat_get(dir_fd, 0, "file").expect("reading file stats");
|
||||
assert_eq!(stat.size, 0, "file size should be 0");
|
||||
let file_stat = wasi::path_filestat_get(dir_fd, 0, "file").expect("reading file stats");
|
||||
assert_eq!(file_stat.size, 0, "file size should be 0");
|
||||
|
||||
// Check path_filestat_set_times
|
||||
let new_mtim = stat.mtim - 100;
|
||||
let new_mtim = file_stat.mtim - 100;
|
||||
wasi::path_filestat_set_times(dir_fd, 0, "file", 0, new_mtim, wasi::FSTFLAGS_MTIM)
|
||||
.expect("path_filestat_set_times should succeed");
|
||||
|
||||
stat = wasi::path_filestat_get(dir_fd, 0, "file")
|
||||
let modified_file_stat = wasi::path_filestat_get(dir_fd, 0, "file")
|
||||
.expect("reading file stats after path_filestat_set_times");
|
||||
assert_eq!(stat.mtim, new_mtim, "mtim should change");
|
||||
assert_eq!(modified_file_stat.mtim, new_mtim, "mtim should change");
|
||||
|
||||
assert_eq!(
|
||||
wasi::path_filestat_set_times(
|
||||
@@ -74,10 +74,14 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
|
||||
);
|
||||
|
||||
// check if the times were untouched
|
||||
stat = wasi::path_filestat_get(dir_fd, 0, "file")
|
||||
let unmodified_file_stat = wasi::path_filestat_get(dir_fd, 0, "file")
|
||||
.expect("reading file stats after ERRNO_INVAL fd_filestat_set_times");
|
||||
assert_eq!(stat.mtim, new_mtim, "mtim should not change");
|
||||
assert_eq!(
|
||||
unmodified_file_stat.mtim, new_mtim,
|
||||
"mtim should not change"
|
||||
);
|
||||
|
||||
// Invalid arguments to set_times:
|
||||
assert_eq!(
|
||||
wasi::path_filestat_set_times(
|
||||
dir_fd,
|
||||
@@ -93,46 +97,8 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
|
||||
"errno should be ERRNO_INVAL"
|
||||
);
|
||||
|
||||
// Create a symlink
|
||||
wasi::path_symlink("file", dir_fd, "symlink").expect("creating symlink to a file");
|
||||
|
||||
// Check path_filestat_set_times on the symlink itself
|
||||
let mut sym_stat = wasi::path_filestat_get(dir_fd, 0, "file").expect("reading file stats");
|
||||
|
||||
let sym_new_mtim = sym_stat.mtim - 200;
|
||||
wasi::path_filestat_set_times(dir_fd, 0, "symlink", 0, sym_new_mtim, wasi::FSTFLAGS_MTIM)
|
||||
.expect("path_filestat_set_times should succeed on symlink");
|
||||
|
||||
sym_stat = wasi::path_filestat_get(dir_fd, 0, "symlink")
|
||||
.expect("reading file stats after path_filestat_set_times");
|
||||
assert_eq!(sym_stat.mtim, sym_new_mtim, "mtim should change");
|
||||
|
||||
// Now, dereference the symlink
|
||||
sym_stat = wasi::path_filestat_get(dir_fd, wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, "symlink")
|
||||
.expect("reading file stats on the dereferenced symlink");
|
||||
assert_eq!(
|
||||
sym_stat.mtim, stat.mtim,
|
||||
"symlink mtim should be equal to pointee's when dereferenced"
|
||||
);
|
||||
|
||||
// Finally, change stat of the original file by dereferencing the symlink
|
||||
wasi::path_filestat_set_times(
|
||||
dir_fd,
|
||||
wasi::LOOKUPFLAGS_SYMLINK_FOLLOW,
|
||||
"symlink",
|
||||
0,
|
||||
sym_stat.mtim,
|
||||
wasi::FSTFLAGS_MTIM,
|
||||
)
|
||||
.expect("path_filestat_set_times should succeed on setting stat on original file");
|
||||
|
||||
stat = wasi::path_filestat_get(dir_fd, 0, "file")
|
||||
.expect("reading file stats after path_filestat_set_times");
|
||||
assert_eq!(stat.mtim, sym_stat.mtim, "mtim should change");
|
||||
|
||||
wasi::fd_close(file_fd).expect("closing a file");
|
||||
wasi::path_unlink_file(dir_fd, "file").expect("removing a file");
|
||||
wasi::path_unlink_file(dir_fd, "symlink").expect("removing a symlink");
|
||||
}
|
||||
fn main() {
|
||||
let mut args = env::args();
|
||||
|
||||
Reference in New Issue
Block a user