aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/filesystem.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-09 06:19:30 +0900
committernsfisis <nsfisis@gmail.com>2026-08-09 06:19:30 +0900
commit880a5eaad9dcdfd31563385f11ba1f63d38cfd14 (patch)
tree6f9de7b2b8331628a74287112711f65ae3eddc52 /crates/shirabe/src/util/filesystem.rs
parentf3d60c7836da0d50d59a22cfd6e4692e3dc75581 (diff)
downloadphp-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.tar.gz
php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.tar.zst
php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.zip
refactor(php-shim): use std::path::MAIN_SEPARATOR over a shim constant
The shim's DIRECTORY_SEPARATOR was hardcoded to "/", so every ported `'\\' === DIRECTORY_SEPARATOR` check compared against a constant that does not track the target platform. std::path::MAIN_SEPARATOR and MAIN_SEPARATOR_STR carry the same meaning as PHP's constant and resolve per platform, so the Windows branches are selected on Windows targets. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/filesystem.rs')
-rw-r--r--crates/shirabe/src/util/filesystem.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 7010fd86..a12c6d64 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -7,13 +7,13 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::filesystem::exception::IOException;
use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, ErrorException, LogicException, PhpMixed, RuntimeException, array_pop,
- basename, chdir, clearstatcache, clearstatcache2, copy, dirname, error_get_last, explode,
- fclose, feof, file_exists, file_get_contents, file_put_contents, fileatime, filemtime,
- filesize, fopen, fread, function_exists, fwrite, implode, is_dir, is_file, is_link,
- is_readable, lstat, mkdir, php_regex, rename, rmdir, rtrim, str_contains, str_repeat,
- str_replace, str_starts_with, strlen, strpos, strtoupper, strtr, substr, substr_count, symlink,
- touch, unlink, usleep, var_export,
+ ErrorException, LogicException, PhpMixed, RuntimeException, array_pop, basename, chdir,
+ clearstatcache, clearstatcache2, copy, dirname, error_get_last, explode, fclose, feof,
+ file_exists, file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen,
+ fread, function_exists, fwrite, implode, is_dir, is_file, is_link, is_readable, lstat, mkdir,
+ php_regex, rename, rmdir, rtrim, str_contains, str_repeat, str_replace, str_starts_with,
+ strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch, unlink, usleep,
+ var_export,
};
use std::path::Path;
@@ -488,7 +488,12 @@ impl Filesystem {
let mut result = true;
for file in &ri {
- let target_path = format!("{}{}{}", target, DIRECTORY_SEPARATOR, ri.get_sub_pathname());
+ let target_path = format!(
+ "{}{}{}",
+ target,
+ std::path::MAIN_SEPARATOR,
+ ri.get_sub_pathname()
+ );
if file.is_dir() {
self.ensure_directory_exists(&target_path)?;
} else {
@@ -1003,7 +1008,7 @@ impl Filesystem {
let cmd = vec![
"mklink".to_string(),
"/J".to_string(),
- str_replace("/", DIRECTORY_SEPARATOR, junction),
+ str_replace("/", std::path::MAIN_SEPARATOR_STR, junction),
Platform::realpath(target),
];
let mut output = String::new();
@@ -1066,8 +1071,8 @@ impl Filesystem {
return Ok(false);
}
let junction = rtrim(
- &str_replace("/", DIRECTORY_SEPARATOR, junction),
- Some(DIRECTORY_SEPARATOR),
+ &str_replace("/", std::path::MAIN_SEPARATOR_STR, junction),
+ Some(std::path::MAIN_SEPARATOR_STR),
);
if !self.is_junction(&junction) {
return Err(IOException::new(