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/src/util/filesystem.rs | 4 ++-- crates/shirabe/src/util/http/curl_downloader.rs | 14 +++++++------- crates/shirabe/src/util/tar.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/shirabe/src/util') diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 51885cc3..daf26e22 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -499,7 +499,7 @@ impl Filesystem { if file.is_dir() { self.ensure_directory_exists(&target_path)?; } else { - result = result && copy(&file.get_pathname(), &target_path); + result = result && copy(file.get_pathname(), &target_path); } } @@ -944,7 +944,7 @@ impl Filesystem { let cwd = Platform::get_cwd(false).unwrap_or_default(); let relative_path = self.find_shortest_path(link, target, false, false); - chdir(&dirname(link)); + chdir(dirname(link)); let result = symlink(&relative_path, link); chdir(&cwd); diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs index 89e9661e..1207dea0 100644 --- a/crates/shirabe/src/util/http/curl_downloader.rs +++ b/crates/shirabe/src/util/http/curl_downloader.rs @@ -296,7 +296,7 @@ impl CurlDownloader { crate::io::DEBUG, ); if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } return Ok(Decision::Retry { url: url.to_string(), @@ -305,7 +305,7 @@ impl CurlDownloader { } if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } // PHP throws a MaxFileSizeExceededException (a TransportException subclass) with // the raw "Maximum allowed download size reached..." message verbatim rather than @@ -368,7 +368,7 @@ impl CurlDownloader { .unwrap_or(0); attributes.insert("retries".to_string(), PhpMixed::Int(retries + 1)); if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } return Ok(Decision::Retry { url: url.to_string(), @@ -392,7 +392,7 @@ impl CurlDownloader { Ok(location) if !location.is_empty() => { attributes.insert("redirects".to_string(), PhpMixed::Int(redirects + 1)); if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } return Ok(Decision::Retry { url: location, @@ -402,7 +402,7 @@ impl CurlDownloader { Ok(_) => {} Err(e) => { if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } return Ok(Decision::Failed(e)); } @@ -440,7 +440,7 @@ impl CurlDownloader { ); attributes.insert("retries".to_string(), PhpMixed::Int(retries + 1)); if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } return Ok(Decision::Retry { url: url.to_string(), @@ -827,7 +827,7 @@ impl CurlDownloader { error_message: &str, ) -> TransportException { if let Some(filename) = filename { - unlink_silent(&format!("{}~", filename)); + unlink_silent(format!("{}~", filename)); } let mut details = String::new(); diff --git a/crates/shirabe/src/util/tar.rs b/crates/shirabe/src/util/tar.rs index 792d1c4f..f5b0ebbe 100644 --- a/crates/shirabe/src/util/tar.rs +++ b/crates/shirabe/src/util/tar.rs @@ -7,7 +7,7 @@ pub struct Tar; impl Tar { pub fn get_composer_json(path_to_archive: &str) -> anyhow::Result> { - let phar = PharData::new(path_to_archive.to_string())?; + let phar = PharData::new(path_to_archive)?; if !phar.valid() { return Ok(None); -- cgit v1.3.1