aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-class-map-generator/src/class_map_generator.rs15
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs3
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/terminal.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/executable_finder.rs19
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/process.rs23
-rw-r--r--crates/shirabe-php-shim/src/fs.rs1
-rw-r--r--crates/shirabe/src/autoload/class_loader.rs28
-rw-r--r--crates/shirabe/src/command/create_project_command.rs10
-rw-r--r--crates/shirabe/src/downloader/archive_downloader.rs15
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs17
-rw-r--r--crates/shirabe/src/downloader/gzip_downloader.rs7
-rw-r--r--crates/shirabe/src/downloader/path_downloader.rs10
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs12
-rw-r--r--crates/shirabe/src/repository/path_repository.rs6
-rw-r--r--crates/shirabe/src/util/filesystem.rs27
-rw-r--r--crates/shirabe/tests/repository/path_repository_test.rs26
19 files changed, 113 insertions, 118 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs
index d1a11c99..30a6ef1e 100644
--- a/crates/shirabe-class-map-generator/src/class_map_generator.rs
+++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs
@@ -7,10 +7,9 @@ use indexmap::indexmap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, InvalidArgumentException, LogicException, PATHINFO_EXTENSION, PHP_INT_MAX,
- RuntimeException, explode, getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_quote,
- realpath, str_replace, str_starts_with, stream_get_wrappers, strlen, strpos, strrpos, strtr,
- substr,
+ InvalidArgumentException, LogicException, PATHINFO_EXTENSION, PHP_INT_MAX, RuntimeException,
+ explode, getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_quote, realpath,
+ str_replace, str_starts_with, stream_get_wrappers, strlen, strpos, strrpos, strtr, substr,
};
use std::path::PathBuf;
@@ -264,10 +263,10 @@ impl ClassMapGenerator {
if let Some(ns_len) = namespace_length {
let namespace = substr(&class, 0, Some((ns_len + 1) as i64));
let class_name = substr(&class, (ns_len + 1) as i64, None);
- sub_path = str_replace("\\", DIRECTORY_SEPARATOR, &namespace)
- + &str_replace("_", DIRECTORY_SEPARATOR, &class_name);
+ sub_path = str_replace("\\", std::path::MAIN_SEPARATOR_STR, &namespace)
+ + &str_replace("_", std::path::MAIN_SEPARATOR_STR, &class_name);
} else {
- sub_path = str_replace("_", DIRECTORY_SEPARATOR, &class);
+ sub_path = str_replace("_", std::path::MAIN_SEPARATOR_STR, &class);
}
} else if namespace_type == "psr-4" {
let sub_namespace = if !base_namespace.is_empty() {
@@ -275,7 +274,7 @@ impl ClassMapGenerator {
} else {
class.clone()
};
- sub_path = str_replace("\\", DIRECTORY_SEPARATOR, &sub_namespace);
+ sub_path = str_replace("\\", std::path::MAIN_SEPARATOR_STR, &sub_namespace);
} else {
return Err(InvalidArgumentException::new(
"$namespaceType must be \"psr-0\" or \"psr-4\"".to_string(),
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
index 2091225d..f5242d9a 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
@@ -685,7 +685,7 @@ impl QuestionHelper {
input_stream: &shirabe_php_shim::PhpResource,
trimmable: bool,
) -> anyhow::Result<Result<String, RuntimeException>> {
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
let mut exe = format!(
"{}/../Resources/bin/hiddeninput.exe",
shirabe_php_shim::dir()
diff --git a/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs
index 9140dbc8..8ee2f186 100644
--- a/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs
@@ -98,8 +98,7 @@ impl StreamOutput {
return false;
}
- if "\\" == shirabe_php_shim::DIRECTORY_SEPARATOR
- && shirabe_php_shim::sapi_windows_vt100_support(stream)
+ if std::path::MAIN_SEPARATOR == '\\' && shirabe_php_shim::sapi_windows_vt100_support(stream)
{
return true;
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/terminal.rs b/crates/shirabe-external-packages/src/symfony/console/terminal.rs
index 7fca27e8..353dffcb 100644
--- a/crates/shirabe-external-packages/src/symfony/console/terminal.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/terminal.rs
@@ -69,7 +69,7 @@ impl Terminal {
let result = shirabe_php_shim::shell_exec(&format!(
"stty 2> {}",
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
"NUL"
} else {
"/dev/null"
@@ -81,7 +81,7 @@ impl Terminal {
}
fn init_dimensions() {
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
let ansicon = shirabe_php_shim::getenv("ANSICON");
let mut matches: Vec<Option<String>> = Vec::new();
if let Some(ansicon) = &ansicon
diff --git a/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs b/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs
index 8834f724..0aba97fb 100644
--- a/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs
+++ b/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs
@@ -201,7 +201,7 @@ impl Filesystem {
if shirabe_php_shim::is_link(&file) {
// See https://bugs.php.net/52176
if !(shirabe_php_shim::unlink(&file)
- || shirabe_php_shim::DIRECTORY_SEPARATOR != "\\"
+ || std::path::MAIN_SEPARATOR != '\\'
|| shirabe_php_shim::rmdir(&file))
&& shirabe_php_shim::file_exists(&file)
{
@@ -272,7 +272,7 @@ impl Filesystem {
let mut origin_dir = origin_dir.to_string();
let mut target_dir = target_dir.to_string();
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
origin_dir = shirabe_php_shim::strtr(&origin_dir, "/", "\\");
target_dir = shirabe_php_shim::strtr(&target_dir, "/", "\\");
diff --git a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
index 3c44b4ad..a00a302c 100644
--- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
@@ -25,7 +25,7 @@ impl ExecutableFinder {
pub fn find(&self, name: &str, default: Option<&str>, extra_dirs: &[String]) -> Option<String> {
// windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
+ if std::path::MAIN_SEPARATOR == '\\'
&& CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str())
{
return Some(name.to_string());
@@ -39,7 +39,7 @@ impl ExecutableFinder {
dirs.extend_from_slice(extra_dirs);
let mut suffixes: Vec<String> = vec![];
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
let path_ext =
shirabe_php_shim::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned());
suffixes = self.suffixes.clone();
@@ -68,13 +68,9 @@ impl ExecutableFinder {
for suffix in &suffixes {
for dir in &dirs {
let dir = if dir.is_empty() { "." } else { dir.as_str() };
- let file = format!(
- "{dir}{}{name}{suffix}",
- shirabe_php_shim::DIRECTORY_SEPARATOR
- );
+ let file = format!("{dir}{}{name}{suffix}", std::path::MAIN_SEPARATOR);
if shirabe_php_shim::is_file(&file)
- && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
- || shirabe_php_shim::is_executable(&file))
+ && (std::path::MAIN_SEPARATOR == '\\' || shirabe_php_shim::is_executable(&file))
{
return Some(file);
}
@@ -88,12 +84,9 @@ impl ExecutableFinder {
}
}
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
+ if std::path::MAIN_SEPARATOR == '\\'
|| name.len()
- != shirabe_php_shim::strcspn(
- name,
- &format!("/{}", shirabe_php_shim::DIRECTORY_SEPARATOR),
- )
+ != shirabe_php_shim::strcspn(name, &format!("/{}", std::path::MAIN_SEPARATOR))
{
return default.map(ToString::to_string);
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
index 72a28e7d..c4236743 100644
--- a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
@@ -17,7 +17,7 @@ pub struct WindowsPipes {
impl WindowsPipes {
pub fn new(_input: PhpMixed) -> Self {
- // Windows-only path: never constructed on POSIX (DIRECTORY_SEPARATOR is "/").
+ // Windows-only path: never constructed on POSIX (MAIN_SEPARATOR is '/').
todo!()
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/process.rs b/crates/shirabe-external-packages/src/symfony/process/process.rs
index 3e4a818f..64ed3a84 100644
--- a/crates/shirabe-external-packages/src/symfony/process/process.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/process.rs
@@ -245,7 +245,7 @@ impl Process {
this.set_input(input)?;
this.set_timeout(timeout)?;
- this.use_file_handles = shirabe_php_shim::DIRECTORY_SEPARATOR == "\\";
+ this.use_file_handles = std::path::MAIN_SEPARATOR == '\\';
Ok(this)
}
@@ -309,7 +309,7 @@ impl Process {
.collect::<Vec<_>>()
.join(" ");
- if shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" {
+ if std::path::MAIN_SEPARATOR != '\\' {
// exec is mandatory to deal with sending a signal to the process
cmd = format!("exec {}", cmd);
}
@@ -318,7 +318,7 @@ impl Process {
CommandLine::String(s) => self.replace_placeholders(s, &env)?,
};
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
commandline = self.prepare_windows_command_line(&commandline, &mut env)?;
} else if !self.use_file_handles && self.is_sigchild_enabled() {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
@@ -414,12 +414,9 @@ impl Process {
loop {
self.check_timeout()?;
let running = self.is_running()
- && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
+ && (std::path::MAIN_SEPARATOR == '\\'
|| self.process_pipes.as_ref().unwrap().are_open());
- self.read_pipes(
- running,
- shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running,
- );
+ self.read_pipes(running, std::path::MAIN_SEPARATOR != '\\' || !running);
if !running {
break;
}
@@ -644,7 +641,7 @@ impl Process {
/// Enables or disables the TTY mode.
pub fn set_tty(&mut self, tty: bool) -> anyhow::Result<&mut Self> {
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" && tty {
+ if std::path::MAIN_SEPARATOR == '\\' && tty {
return Err(RuntimeException::new(
"TTY mode is not supported on Windows platform.".to_string(),
)
@@ -743,7 +740,7 @@ impl Process {
/// Creates the descriptors needed by the proc_open.
fn get_descriptors(&mut self) -> Vec<Descriptor> {
// TODO(plugin): $this->input instanceof \Iterator -> rewind() is not modeled.
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
self.process_pipes = Some(Box::new(WindowsPipes::new(self.input.clone())));
} else {
self.process_pipes = Some(Box::new(UnixPipes::new(
@@ -818,7 +815,7 @@ impl Process {
self.read_pipes(
running && blocking,
- shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running,
+ std::path::MAIN_SEPARATOR != '\\' || !running,
);
if !self.fallback_status.is_empty() && self.is_sigchild_enabled() {
@@ -999,7 +996,7 @@ impl Process {
Some(pid) => pid,
};
- if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ if std::path::MAIN_SEPARATOR == '\\' {
let mut output: Vec<String> = Vec::new();
let mut exit_code: i64 = 0;
shirabe_php_shim::exec(
@@ -1192,7 +1189,7 @@ impl Process {
None | Some("") => return "\"\"".to_string(),
Some(a) => a,
};
- if shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" {
+ if std::path::MAIN_SEPARATOR != '\\' {
return format!("'{}'", argument.replace('\'', "'\\''"));
}
let mut argument = argument.to_string();
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index 00ed6de3..575ce26a 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -20,7 +20,6 @@ pub const PATHINFO_DIRNAME: i64 = 1;
pub const PATHINFO_BASENAME: i64 = 2;
pub const PATH_SEPARATOR: &str = ":";
-pub const DIRECTORY_SEPARATOR: &str = "/";
/// PHP `PHP_MAXPATHLEN`: the platform's `MAXPATHLEN` (`MAX_PATH` on Windows).
pub const PHP_MAXPATHLEN: i64 = if cfg!(windows) {
diff --git a/crates/shirabe/src/autoload/class_loader.rs b/crates/shirabe/src/autoload/class_loader.rs
index 47b6ee4c..21473fb9 100644
--- a/crates/shirabe/src/autoload/class_loader.rs
+++ b/crates/shirabe/src/autoload/class_loader.rs
@@ -2,9 +2,8 @@
use indexmap::IndexMap;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, InvalidArgumentException, PhpMixed, defined, file_exists, include_file,
- spl_autoload_register, spl_autoload_unregister, stream_resolve_include_path, strlen, strpos,
- strrpos, strtr, substr,
+ InvalidArgumentException, PhpMixed, defined, file_exists, include_file, spl_autoload_register,
+ spl_autoload_unregister, stream_resolve_include_path, strlen, strpos, strrpos, strtr, substr,
};
use std::sync::{LazyLock, Mutex};
@@ -366,7 +365,11 @@ impl ClassLoader {
fn find_file_with_extension(&self, class: &str, ext: &str) -> Option<String> {
// PSR-4 lookup
- let logical_path_psr4 = format!("{}{}", strtr(class, "\\", DIRECTORY_SEPARATOR), ext);
+ let logical_path_psr4 = format!(
+ "{}{}",
+ strtr(class, "\\", std::path::MAIN_SEPARATOR_STR),
+ ext
+ );
let first = class.chars().next().unwrap_or('\0').to_string();
if self.prefix_lengths_psr4.contains_key(&first) {
@@ -382,7 +385,7 @@ impl ClassLoader {
if let Some(dirs) = self.prefix_dirs_psr4.get(&search) {
let path_end = format!(
"{}{}",
- DIRECTORY_SEPARATOR,
+ std::path::MAIN_SEPARATOR,
substr(&logical_path_psr4, (last_pos + 1) as i64, None)
);
for dir in dirs {
@@ -397,7 +400,7 @@ impl ClassLoader {
// PSR-4 fallback dirs
for dir in &self.fallback_dirs_psr4 {
- let file = format!("{}{}{}", dir, DIRECTORY_SEPARATOR, logical_path_psr4);
+ let file = format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr4);
if file_exists(&file) {
return Some(file);
}
@@ -413,19 +416,24 @@ impl ClassLoader {
strtr(
&substr(&logical_path_psr4, (pos + 1) as i64, None),
"_",
- DIRECTORY_SEPARATOR
+ std::path::MAIN_SEPARATOR_STR,
)
);
} else {
// PEAR-like class name
- logical_path_psr0 = format!("{}{}", strtr(class, "_", DIRECTORY_SEPARATOR), ext);
+ logical_path_psr0 = format!(
+ "{}{}",
+ strtr(class, "_", std::path::MAIN_SEPARATOR_STR),
+ ext
+ );
}
if let Some(prefixes) = self.prefixes_psr0.get(&first) {
for (prefix, dirs) in prefixes {
if Some(0) == strpos(class, prefix) {
for dir in dirs {
- let file = format!("{}{}{}", dir, DIRECTORY_SEPARATOR, logical_path_psr0);
+ let file =
+ format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr0);
if file_exists(&file) {
return Some(file);
}
@@ -436,7 +444,7 @@ impl ClassLoader {
// PSR-0 fallback dirs
for dir in &self.fallback_dirs_psr0 {
- let file = format!("{}{}{}", dir, DIRECTORY_SEPARATOR, logical_path_psr0);
+ let file = format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr0);
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 267c866e..3849d93d 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -44,9 +44,9 @@ use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, InvalidArgumentException, PhpMixed, RuntimeException,
- UnexpectedValueException, array_pop, chdir, explode_with_limit, file_exists, getcwd,
- impl_php_class, implode, is_dir, is_file, mkdir, realpath, rtrim, strtolower, unlink,
+ InvalidArgumentException, PhpMixed, RuntimeException, UnexpectedValueException, array_pop,
+ chdir, explode_with_limit, file_exists, getcwd, impl_php_class, implode, is_dir, is_file,
+ mkdir, realpath, rtrim, strtolower, unlink,
};
use std::path::PathBuf;
@@ -461,7 +461,7 @@ impl CreateProjectCommand {
format!(
"{}{}{}",
Platform::get_cwd(false)?,
- DIRECTORY_SEPARATOR,
+ std::path::MAIN_SEPARATOR,
array_pop(&mut parts).unwrap_or_default()
)
}
@@ -477,7 +477,7 @@ impl CreateProjectCommand {
directory = format!(
"{}{}{}",
Platform::get_cwd(false)?,
- DIRECTORY_SEPARATOR,
+ std::path::MAIN_SEPARATOR,
directory
);
}
diff --git a/crates/shirabe/src/downloader/archive_downloader.rs b/crates/shirabe/src/downloader/archive_downloader.rs
index d2ee4a75..097fc1af 100644
--- a/crates/shirabe/src/downloader/archive_downloader.rs
+++ b/crates/shirabe/src/downloader/archive_downloader.rs
@@ -11,8 +11,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, PhpMixed, RuntimeException, bin2hex, file_exists, is_dir, random_bytes,
- realpath,
+ PhpMixed, RuntimeException, bin2hex, file_exists, is_dir, random_bytes, realpath,
};
use std::path::{Path, PathBuf};
@@ -92,13 +91,11 @@ pub trait ArchiveDownloader {
.filesystem
.borrow()
.normalize_path(&vendor_dir)
- .contains(
- &self
- .inner()
- .filesystem
- .borrow()
- .normalize_path(&format!("{}{}", path, DIRECTORY_SEPARATOR)),
- )
+ .contains(&self.inner().filesystem.borrow().normalize_path(&format!(
+ "{}{}",
+ path,
+ std::path::MAIN_SEPARATOR
+ )))
{
self.inner()
.filesystem
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 9b86ee56..ab9c3672 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -27,10 +27,10 @@ use crate::util::sync_executor;
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, InvalidArgumentException, PATHINFO_BASENAME, PATHINFO_EXTENSION,
- PHP_URL_PATH, PhpMixed, RuntimeException, UnexpectedValueException, array_search, file_exists,
- filesize, get_class, hash, hash_file, impl_php_class, is_dir, is_executable, parse_url,
- pathinfo, realpath, rtrim, spl_object_hash, strlen, strpos, strtr, trim, umask, usleep,
+ InvalidArgumentException, PATHINFO_BASENAME, PATHINFO_EXTENSION, PHP_URL_PATH, PhpMixed,
+ RuntimeException, UnexpectedValueException, array_search, file_exists, filesize, get_class,
+ hash, hash_file, impl_php_class, is_dir, is_executable, parse_url, pathinfo, realpath, rtrim,
+ spl_object_hash, strlen, strpos, strtr, trim, umask, usleep,
};
use std::sync::{LazyLock, Mutex};
@@ -744,10 +744,11 @@ impl DownloaderInterface for FileDownloader {
// but in that case we ensure the directory is empty already in ProjectInstaller so no need to empty it here.
if !{
let normalized_vendor = self.filesystem.borrow_mut().normalize_path(&vendor_dir);
- let normalized_path = self
- .filesystem
- .borrow()
- .normalize_path(&format!("{}{}", path, DIRECTORY_SEPARATOR));
+ let normalized_path = self.filesystem.borrow().normalize_path(&format!(
+ "{}{}",
+ path,
+ std::path::MAIN_SEPARATOR
+ ));
strpos(&normalized_vendor, &normalized_path).is_some()
} {
self.filesystem.borrow_mut().empty_directory(path, true)?;
diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs
index 9473deff..3ddca2a4 100644
--- a/crates/shirabe/src/downloader/gzip_downloader.rs
+++ b/crates/shirabe/src/downloader/gzip_downloader.rs
@@ -14,9 +14,8 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, PATHINFO_FILENAME, PHP_URL_PATH, PhpMixed, RuntimeException,
- extension_loaded, fclose, fopen, fwrite, gzclose, gzopen, gzread, impl_php_class, implode,
- parse_url, pathinfo, strtr,
+ PATHINFO_FILENAME, PHP_URL_PATH, PhpMixed, RuntimeException, extension_loaded, fclose, fopen,
+ fwrite, gzclose, gzopen, gzread, impl_php_class, implode, parse_url, pathinfo, strtr,
};
#[derive(Debug)]
@@ -91,7 +90,7 @@ impl ArchiveDownloader for GzipDownloader {
.unwrap_or(""),
PATHINFO_FILENAME,
);
- let target_filepath = format!("{}{}{}", path, DIRECTORY_SEPARATOR, filename);
+ let target_filepath = format!("{}{}{}", path, std::path::MAIN_SEPARATOR, filename);
if !Platform::is_windows() {
let command = vec![
diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs
index 9449e74a..4be835cd 100644
--- a/crates/shirabe/src/downloader/path_downloader.rs
+++ b/crates/shirabe/src/downloader/path_downloader.rs
@@ -23,8 +23,8 @@ use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::filesystem::Filesystem as SymfonyFilesystem;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, PHP_WINDOWS_VERSION_MAJOR, PHP_WINDOWS_VERSION_MINOR, PhpMixed,
- RuntimeException, file_exists, function_exists, impl_php_class, is_dir, realpath,
+ PHP_WINDOWS_VERSION_MAJOR, PHP_WINDOWS_VERSION_MINOR, PhpMixed, RuntimeException, file_exists,
+ function_exists, impl_php_class, is_dir, realpath,
};
#[derive(Debug)]
@@ -261,9 +261,9 @@ impl DownloaderInterface for PathDownloader {
if format!(
"{}{}",
realpath(&path).unwrap_or_default(),
- DIRECTORY_SEPARATOR
+ std::path::MAIN_SEPARATOR
)
- .starts_with(&format!("{}{}", real_url, DIRECTORY_SEPARATOR))
+ .starts_with(&format!("{}{}", real_url, std::path::MAIN_SEPARATOR))
{
// IMPORTANT NOTICE: If you wish to change this, don't. You are wasting your time and ours.
//
@@ -383,7 +383,7 @@ impl DownloaderInterface for PathDownloader {
format!(
"{}{}{}",
Platform::get_cwd(false)?,
- DIRECTORY_SEPARATOR,
+ std::path::MAIN_SEPARATOR,
path
)
} else {
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index c481f13f..bc565ea0 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -12,10 +12,10 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::process::ExecutableFinder;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- CmpOp, DIRECTORY_SEPARATOR, ErrorException, PhpMixed, RuntimeException,
- UnexpectedValueException, ZipArchive, bin2hex, class_exists, file_exists, file_get_contents,
- filesize, function_exists, hash_file, impl_php_class, is_file, json_encode, php_regex,
- random_int, str_contains, str_replace, strlen, substr, version_compare,
+ CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive,
+ bin2hex, class_exists, file_exists, file_get_contents, filesize, function_exists, hash_file,
+ impl_php_class, is_file, json_encode, php_regex, random_int, str_contains, str_replace, strlen,
+ substr, version_compare,
};
use std::sync::Mutex;
@@ -84,8 +84,8 @@ impl ZipDownloader {
let map: IndexMap<&str, String> = [
// normalize separators to backslashes to avoid problems with 7-zip on windows
// see https://github.com/composer/composer/issues/10058
- ("%file%", file.replace('/', DIRECTORY_SEPARATOR)),
- ("%path%", path.replace('/', DIRECTORY_SEPARATOR)),
+ ("%file%", file.replace('/', std::path::MAIN_SEPARATOR_STR)),
+ ("%path%", path.replace('/', std::path::MAIN_SEPARATOR_STR)),
]
.into_iter()
.collect();
diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs
index 46b7f95f..13c512aa 100644
--- a/crates/shirabe/src/repository/path_repository.rs
+++ b/crates/shirabe/src/repository/path_repository.rs
@@ -25,8 +25,8 @@ use crate::util::Url;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, GLOB_BRACE, GLOB_MARK, GLOB_ONLYDIR, PhpMixed, RuntimeException, defined,
- file_exists, file_get_contents, glob_with_flags, hash, php_regex, realpath, serialize,
+ GLOB_BRACE, GLOB_MARK, GLOB_ONLYDIR, PhpMixed, RuntimeException, defined, file_exists,
+ file_get_contents, glob_with_flags, hash, php_regex, realpath, serialize,
};
#[derive(Debug)]
@@ -378,7 +378,7 @@ impl PathRepository {
Ok(glob_with_flags(&self.url, flags)
.into_iter()
.map(|val| {
- val.replace(DIRECTORY_SEPARATOR, "/")
+ val.replace(std::path::MAIN_SEPARATOR, "/")
.trim_end_matches('/')
.to_string()
})
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(
diff --git a/crates/shirabe/tests/repository/path_repository_test.rs b/crates/shirabe/tests/repository/path_repository_test.rs
index 0631e7f7..bd24504d 100644
--- a/crates/shirabe/tests/repository/path_repository_test.rs
+++ b/crates/shirabe/tests/repository/path_repository_test.rs
@@ -9,9 +9,7 @@ use shirabe::repository::PathRepository;
use shirabe::util::http_downloader::HttpDownloader;
use shirabe::util::r#loop::Loop;
use shirabe::util::{Platform, ProcessExecutor};
-use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, PhpMixed, file_get_contents, hash, realpath, serialize,
-};
+use shirabe_php_shim::{PhpMixed, file_get_contents, hash, realpath, serialize};
fn fixtures_dir() -> String {
format!(
@@ -51,8 +49,8 @@ fn coordinates(pairs: Vec<(&str, PhpMixed)>) -> IndexMap<String, PhpMixed> {
#[test]
fn test_load_package_from_file_system_with_incorrect_path() {
- let repository_url =
- [fixtures_dir(), "path".to_string(), "missing".to_string()].join(DIRECTORY_SEPARATOR);
+ let repository_url = [fixtures_dir(), "path".to_string(), "missing".to_string()]
+ .join(std::path::MAIN_SEPARATOR_STR);
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
assert!(repository.__get_packages().is_err());
@@ -65,7 +63,7 @@ fn test_load_package_from_file_system_with_version() {
"path".to_string(),
"with-version".to_string(),
]
- .join(DIRECTORY_SEPARATOR);
+ .join(std::path::MAIN_SEPARATOR_STR);
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
repository.__get_packages().unwrap();
@@ -85,7 +83,7 @@ fn test_load_package_from_file_system_without_version() {
"path".to_string(),
"without-version".to_string(),
]
- .join(DIRECTORY_SEPARATOR);
+ .join(std::path::MAIN_SEPARATOR_STR);
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
let packages = repository.__get_packages().unwrap();
@@ -102,7 +100,7 @@ fn test_load_package_from_file_system_without_version() {
#[test]
fn test_load_package_from_file_system_with_wildcard() {
let repository_url =
- [fixtures_dir(), "path".to_string(), "*".to_string()].join(DIRECTORY_SEPARATOR);
+ [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR);
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
let packages = repository.__get_packages().unwrap();
@@ -140,7 +138,7 @@ fn test_load_package_with_explicit_versions() {
let options = coordinates(vec![("versions", PhpMixed::Array(versions))]);
let repository_url =
- [fixtures_dir(), "path".to_string(), "*".to_string()].join(DIRECTORY_SEPARATOR);
+ [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR);
let mut repository = create_path_repo(coordinates(vec![
("url", PhpMixed::String(repository_url)),
("options", PhpMixed::Array(options)),
@@ -207,13 +205,13 @@ fn test_url_remains_relative() {
"path".to_string(),
"with-version".to_string(),
]
- .join(DIRECTORY_SEPARATOR);
+ .join(std::path::MAIN_SEPARATOR_STR);
// getcwd() not necessarily match __DIR__
// PHP Bug https://bugs.php.net/bug.php?id=73797
let cwd = realpath(realpath(Platform::get_cwd(false).unwrap()).unwrap_or_default())
.unwrap_or_default();
let relative_url = repository_url[cwd.len().min(repository_url.len())..]
- .trim_start_matches(DIRECTORY_SEPARATOR)
+ .trim_start_matches(std::path::MAIN_SEPARATOR)
.to_string();
let mut repository = create_path_repo(coordinates(vec![(
@@ -228,7 +226,7 @@ fn test_url_remains_relative() {
assert_eq!("test/path-versioned", package.get_name());
// Convert platform specific separators back to generic URL slashes
- let relative_url = relative_url.replace(DIRECTORY_SEPARATOR, "/");
+ let relative_url = relative_url.replace(std::path::MAIN_SEPARATOR, "/");
assert_eq!(Some(relative_url), package.get_dist_url());
}
@@ -236,7 +234,7 @@ fn test_url_remains_relative() {
fn test_reference_none() {
let options = coordinates(vec![("reference", PhpMixed::String("none".to_string()))]);
let repository_url =
- [fixtures_dir(), "path".to_string(), "*".to_string()].join(DIRECTORY_SEPARATOR);
+ [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR);
let mut repository = create_path_repo(coordinates(vec![
("url", PhpMixed::String(repository_url)),
("options", PhpMixed::Array(options)),
@@ -257,7 +255,7 @@ fn test_reference_config() {
("relative", PhpMixed::Bool(true)),
]);
let repository_url =
- [fixtures_dir(), "path".to_string(), "*".to_string()].join(DIRECTORY_SEPARATOR);
+ [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR);
let mut repository = create_path_repo(coordinates(vec![
("url", PhpMixed::String(repository_url)),
("options", PhpMixed::Array(options.clone())),