From 92d2199afcecd0056e82d2559700769715401ef0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 03:46:41 +0900 Subject: refactor(php-shim): take filesystem paths as impl AsRef The shim's filesystem entry points took `&str` even though each one resolves to a local path through `std::fs` or a syscall, so callers holding a `PathBuf` had to stringify it at the call site. They now take `impl AsRef`, the form `file_exists`, `is_dir`, `unlink` and the rest of the already-converted set use. `Phar`, `PharData` and `ZipArchive` keep their archive path as a `PathBuf`. `PharData::compress` names the compressed sibling by appending the suffix to the file name rather than formatting the path into a `String`. Arguments PHP resolves through a stream wrapper (`fopen`, `file_put_contents`, `include`) still take `&str`, as do the byte-string operations (`dirname`, `basename`, `pathinfo`) and archive-internal entry names, which are `/`-joined logical names rather than OS paths. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/tests/util/filesystem_test.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/shirabe/tests/util') diff --git a/crates/shirabe/tests/util/filesystem_test.rs b/crates/shirabe/tests/util/filesystem_test.rs index 2e160e87..5bb44598 100644 --- a/crates/shirabe/tests/util/filesystem_test.rs +++ b/crates/shirabe/tests/util/filesystem_test.rs @@ -433,7 +433,7 @@ fn test_remove_directory_php() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/level1/level2"), 0o777, true); + mkdir(format!("{working_dir}/level1/level2"), 0o777, true); file_put_contents( &format!("{working_dir}/level1/level2/hello.txt"), b"hello world", @@ -509,10 +509,10 @@ fn test_unlink_symlinked_directory() { let working_dir = tempfile::TempDir::new().unwrap(); let basepath = working_dir.path().to_str().unwrap().to_string(); let symlinked = format!("{basepath}/linked"); - mkdir(&format!("{basepath}/real"), 0o777, true); - touch(&format!("{basepath}/real/FILE")); + mkdir(format!("{basepath}/real"), 0o777, true); + touch(format!("{basepath}/real/FILE")); - let result = symlink(&format!("{basepath}/real"), &symlinked); + let result = symlink(format!("{basepath}/real"), &symlinked); if !result { // Symbolic links for directories not supported on this platform. @@ -534,12 +534,12 @@ fn test_remove_symlinked_directory_with_trailing_slash() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/real"), 0o777, true); - touch(&format!("{working_dir}/real/FILE")); + mkdir(format!("{working_dir}/real"), 0o777, true); + touch(format!("{working_dir}/real/FILE")); let symlinked = format!("{working_dir}/linked"); let symlinked_trailing_slash = format!("{symlinked}/"); - let result = symlink(&format!("{working_dir}/real"), &symlinked); + let result = symlink(format!("{working_dir}/real"), &symlinked); if !result { // Symbolic links for directories not supported on this platform. @@ -567,7 +567,7 @@ fn test_junctions() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/real/nesting/testing"), 0o777, true); + mkdir(format!("{working_dir}/real/nesting/testing"), 0o777, true); let mut fs = Filesystem::new(None); // Non-Windows systems do not support this and will return false on all tests, and an exception @@ -625,7 +625,7 @@ fn test_override_junctions() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/real/nesting/testing"), 0o777, true); + mkdir(format!("{working_dir}/real/nesting/testing"), 0o777, true); let mut fs = Filesystem::new(None); let old_target = format!("{working_dir}/real/nesting/testing"); @@ -667,8 +667,8 @@ fn test_copy() { let unique_tmp = tempfile::TempDir::new().unwrap(); let test_file = format!("{}/composer_test_file", unique_tmp.path().to_str().unwrap()); - mkdir(&format!("{working_dir}/foo/bar"), 0o777, true); - mkdir(&format!("{working_dir}/foo/baz"), 0o777, true); + mkdir(format!("{working_dir}/foo/bar"), 0o777, true); + mkdir(format!("{working_dir}/foo/baz"), 0o777, true); file_put_contents(&format!("{working_dir}/foo/foo.file"), b"foo"); file_put_contents(&format!("{working_dir}/foo/bar/foobar.file"), b"foobar"); file_put_contents(&format!("{working_dir}/foo/baz/foobaz.file"), b"foobaz"); @@ -722,8 +722,8 @@ fn test_copy_then_remove() { let unique_tmp = tempfile::TempDir::new().unwrap(); let test_file = format!("{}/composer_test_file", unique_tmp.path().to_str().unwrap()); - mkdir(&format!("{working_dir}/foo/bar"), 0o777, true); - mkdir(&format!("{working_dir}/foo/baz"), 0o777, true); + mkdir(format!("{working_dir}/foo/bar"), 0o777, true); + mkdir(format!("{working_dir}/foo/baz"), 0o777, true); file_put_contents(&format!("{working_dir}/foo/foo.file"), b"foo"); file_put_contents(&format!("{working_dir}/foo/bar/foobar.file"), b"foobar"); file_put_contents(&format!("{working_dir}/foo/baz/foobaz.file"), b"foobaz"); -- cgit v1.3.1