diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:39:08 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:39:08 +0900 |
| commit | ff17dcdb757656c5e81b10070a7bbcc4ef3e97f7 (patch) | |
| tree | b11bf68b9466242e6021bef0e3b0e98e566647e2 /crates/shirabe/src | |
| parent | 6dd09abb33d86e1aa737667f9e15a18ed41d52e1 (diff) | |
| download | php-shirabe-ff17dcdb757656c5e81b10070a7bbcc4ef3e97f7.tar.gz php-shirabe-ff17dcdb757656c5e81b10070a7bbcc4ef3e97f7.tar.zst php-shirabe-ff17dcdb757656c5e81b10070a7bbcc4ef3e97f7.zip | |
refactor(path): build paths with Path::join
Concatenating a directory, MAIN_SEPARATOR and a component reimplements
what Path::join already does. Joining directly also drops the separator
from the intermediate values it used to be baked into, such as
ClassLoader's $pathEnd.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src')
| -rw-r--r-- | crates/shirabe/src/autoload/class_loader.rs | 31 | ||||
| -rw-r--r-- | crates/shirabe/src/command/create_project_command.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/gzip_downloader.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/path_downloader.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe/src/util/filesystem.rs | 11 |
5 files changed, 46 insertions, 35 deletions
diff --git a/crates/shirabe/src/autoload/class_loader.rs b/crates/shirabe/src/autoload/class_loader.rs index 21473fb9..023812ce 100644 --- a/crates/shirabe/src/autoload/class_loader.rs +++ b/crates/shirabe/src/autoload/class_loader.rs @@ -383,13 +383,13 @@ impl ClassLoader { sub_path = substr(&sub_path, 0, Some(last_pos as i64)); let search = format!("{}\\", sub_path); if let Some(dirs) = self.prefix_dirs_psr4.get(&search) { - let path_end = format!( - "{}{}", - std::path::MAIN_SEPARATOR, - substr(&logical_path_psr4, (last_pos + 1) as i64, None) - ); + let path_end = substr(&logical_path_psr4, (last_pos + 1) as i64, None); for dir in dirs { - let file = format!("{}{}", dir, path_end); + let file = std::path::Path::new(dir) + .join(&path_end) + .into_os_string() + .into_string() + .unwrap(); if file_exists(&file) { return Some(file); } @@ -400,7 +400,11 @@ impl ClassLoader { // PSR-4 fallback dirs for dir in &self.fallback_dirs_psr4 { - let file = format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr4); + let file = std::path::Path::new(dir) + .join(&logical_path_psr4) + .into_os_string() + .into_string() + .unwrap(); if file_exists(&file) { return Some(file); } @@ -432,8 +436,11 @@ impl ClassLoader { for (prefix, dirs) in prefixes { if Some(0) == strpos(class, prefix) { for dir in dirs { - let file = - format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr0); + let file = std::path::Path::new(dir) + .join(&logical_path_psr0) + .into_os_string() + .into_string() + .unwrap(); if file_exists(&file) { return Some(file); } @@ -444,7 +451,11 @@ impl ClassLoader { // PSR-0 fallback dirs for dir in &self.fallback_dirs_psr0 { - let file = format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr0); + let file = std::path::Path::new(dir) + .join(&logical_path_psr0) + .into_os_string() + .into_string() + .unwrap(); if file_exists(&file) { return Some(file); } diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index 3849d93d..048d7b59 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -458,12 +458,11 @@ impl CreateProjectCommand { let mut directory = match directory { None => { let mut parts = explode_with_limit("/", &name, 2); - format!( - "{}{}{}", - Platform::get_cwd(false)?, - std::path::MAIN_SEPARATOR, - array_pop(&mut parts).unwrap_or_default() - ) + std::path::Path::new(&Platform::get_cwd(false)?) + .join(array_pop(&mut parts).unwrap_or_default()) + .into_os_string() + .into_string() + .unwrap() } Some(directory) => directory, }; @@ -474,12 +473,11 @@ impl CreateProjectCommand { )))); let fs = std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(Some(process)))); if !fs.borrow().is_absolute_path(&directory) { - directory = format!( - "{}{}{}", - Platform::get_cwd(false)?, - std::path::MAIN_SEPARATOR, - directory - ); + directory = std::path::Path::new(&Platform::get_cwd(false)?) + .join(&directory) + .into_os_string() + .into_string() + .unwrap(); } if directory.is_empty() { return Err(UnexpectedValueException::new( diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs index 3ddca2a4..962c5bb8 100644 --- a/crates/shirabe/src/downloader/gzip_downloader.rs +++ b/crates/shirabe/src/downloader/gzip_downloader.rs @@ -90,7 +90,11 @@ impl ArchiveDownloader for GzipDownloader { .unwrap_or(""), PATHINFO_FILENAME, ); - let target_filepath = format!("{}{}{}", path, std::path::MAIN_SEPARATOR, filename); + let target_filepath = std::path::Path::new(path) + .join(&filename) + .into_os_string() + .into_string() + .unwrap(); if !Platform::is_windows() { let command = vec