aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/executable_finder.rs6
-rw-r--r--crates/shirabe/src/autoload/class_loader.rs31
-rw-r--r--crates/shirabe/src/command/create_project_command.rs22
-rw-r--r--crates/shirabe/src/downloader/gzip_downloader.rs6
-rw-r--r--crates/shirabe/src/downloader/path_downloader.rs11
-rw-r--r--crates/shirabe/src/util/filesystem.rs11
-rw-r--r--crates/shirabe/tests/repository/path_repository_test.rs81
7 files changed, 103 insertions, 65 deletions
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 cd7d378f..309cdf7e 100644
--- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
@@ -66,7 +66,11 @@ 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}", std::path::MAIN_SEPARATOR);
+ let file = std::path::Path::new(dir)
+ .join(format!("{name}{suffix}"))
+ .into_os_string()
+ .into_string()
+ .unwrap();
if shirabe_php_shim::is_file(&file)
&& (cfg!(windows) || shirabe_php_shim::is_executable(&file))
{
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![
diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs
index 4be835cd..6a496c6a 100644
--- a/crates/shirabe/src/downloader/path_downloader.rs
+++ b/crates/shirabe/src/downloader/path_downloader.rs
@@ -380,12 +380,11 @@ impl DownloaderInterface for PathDownloader {
{
let absolute_path =
if !self.inner.filesystem.borrow_mut().is_absolute_path(&path) {
- format!(
- "{}{}{}",
- Platform::get_cwd(false)?,
- std::path::MAIN_SEPARATOR,
- path
- )
+ std::path::Path::new(&Platform::get_cwd(false)?)
+ .join(&path)
+ .into_os_string()
+ .into_string()
+ .unwrap()
} else {
path.clone()
};
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index a12c6d64..2c4cbcc6 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -488,12 +488,11 @@ impl Filesystem {
let mut result = true;
for file in &ri {
- let target_path = format!(
- "{}{}{}",
- target,
- std::path::MAIN_SEPARATOR,
- ri.get_sub_pathname()
- );
+ let target_path = Path::new(&target)
+ .join(ri.get_sub_pathname())
+ .into_os_string()
+ .into_string()
+ .unwrap();
if file.is_dir() {
self.ensure_directory_exists(&target_path)?;
} else {
diff --git a/crates/shirabe/tests/repository/path_repository_test.rs b/crates/shirabe/tests/repository/path_repository_test.rs
index bd24504d..c892ddc7 100644
--- a/crates/shirabe/tests/repository/path_repository_test.rs
+++ b/crates/shirabe/tests/repository/path_repository_test.rs
@@ -10,6 +10,7 @@ use shirabe::util::http_downloader::HttpDownloader;
use shirabe::util::r#loop::Loop;
use shirabe::util::{Platform, ProcessExecutor};
use shirabe_php_shim::{PhpMixed, file_get_contents, hash, realpath, serialize};
+use std::path::Path;
fn fixtures_dir() -> String {
format!(
@@ -49,8 +50,12 @@ 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(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("missing")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
assert!(repository.__get_packages().is_err());
@@ -58,12 +63,12 @@ fn test_load_package_from_file_system_with_incorrect_path() {
#[test]
fn test_load_package_from_file_system_with_version() {
- let repository_url = [
- fixtures_dir(),
- "path".to_string(),
- "with-version".to_string(),
- ]
- .join(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("with-version")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
repository.__get_packages().unwrap();
@@ -78,12 +83,12 @@ fn test_load_package_from_file_system_with_version() {
#[test]
fn test_load_package_from_file_system_without_version() {
- let repository_url = [
- fixtures_dir(),
- "path".to_string(),
- "without-version".to_string(),
- ]
- .join(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("without-version")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
let packages = repository.__get_packages().unwrap();
@@ -99,8 +104,12 @@ 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(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("*")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository =
create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))]));
let packages = repository.__get_packages().unwrap();
@@ -137,8 +146,12 @@ 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(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("*")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository = create_path_repo(coordinates(vec![
("url", PhpMixed::String(repository_url)),
("options", PhpMixed::Array(options)),
@@ -198,14 +211,16 @@ fn test_url_remains_relative() {
// realpath() does not fully expand the paths
// PHP Bug https://bugs.php.net/bug.php?id=72642
- let repository_url = [
- realpath(realpath(fixtures_dir().replace("/Fixtures", "")).unwrap_or_default())
+ let repository_url = Path::new(
+ &realpath(realpath(fixtures_dir().replace("/Fixtures", "")).unwrap_or_default())
.unwrap_or_default(),
- "Fixtures".to_string(),
- "path".to_string(),
- "with-version".to_string(),
- ]
- .join(std::path::MAIN_SEPARATOR_STR);
+ )
+ .join("Fixtures")
+ .join("path")
+ .join("with-version")
+ .into_os_string()
+ .into_string()
+ .unwrap();
// 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())
@@ -233,8 +248,12 @@ fn test_url_remains_relative() {
#[test]
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(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("*")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository = create_path_repo(coordinates(vec![
("url", PhpMixed::String(repository_url)),
("options", PhpMixed::Array(options)),
@@ -254,8 +273,12 @@ fn test_reference_config() {
("reference", PhpMixed::String("config".to_string())),
("relative", PhpMixed::Bool(true)),
]);
- let repository_url =
- [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR);
+ let repository_url = Path::new(&fixtures_dir())
+ .join("path")
+ .join("*")
+ .into_os_string()
+ .into_string()
+ .unwrap();
let mut repository = create_path_repo(coordinates(vec![
("url", PhpMixed::String(repository_url)),
("options", PhpMixed::Array(options.clone())),