1 #![expect(unsafe_op_in_unsafe_fn, reason = "old code, not worth updating yet")]
2 
3 use std::{env, process};
4 use test_programs::preview1::open_scratch_directory;
5 
test_path_rename_trailing_slashes(dir_fd: wasip1::Fd)6 unsafe fn test_path_rename_trailing_slashes(dir_fd: wasip1::Fd) {
7     // Test renaming a directory with a trailing slash in the name.
8     wasip1::path_create_directory(dir_fd, "source").expect("creating a directory");
9     wasip1::path_rename(dir_fd, "source/", dir_fd, "target")
10         .expect("renaming a directory with a trailing slash in the source name");
11     wasip1::path_rename(dir_fd, "target", dir_fd, "source/")
12         .expect("renaming a directory with a trailing slash in the destination name");
13     wasip1::path_rename(dir_fd, "source/", dir_fd, "target/")
14         .expect("renaming a directory with a trailing slash in the source and destination names");
15     wasip1::path_rename(dir_fd, "target", dir_fd, "source")
16         .expect("renaming a directory with no trailing slashes at all should work");
17     wasip1::path_remove_directory(dir_fd, "source").expect("removing the directory");
18 }
19 
main()20 fn main() {
21     let mut args = env::args();
22     let prog = args.next().unwrap();
23     let arg = if let Some(arg) = args.next() {
24         arg
25     } else {
26         eprintln!("usage: {prog} <scratch directory>");
27         process::exit(1);
28     };
29 
30     // Open scratch directory
31     let dir_fd = match open_scratch_directory(&arg) {
32         Ok(dir_fd) => dir_fd,
33         Err(err) => {
34             eprintln!("{err}");
35             process::exit(1)
36         }
37     };
38 
39     // Run the tests.
40     unsafe { test_path_rename_trailing_slashes(dir_fd) }
41 }
42