aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/filesystem.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/util/filesystem.rs')
-rw-r--r--crates/shirabe/src/util/filesystem.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index ae19a998..41b81b7b 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -8,9 +8,9 @@ use shirabe_php_shim::{
chdir, clearstatcache, clearstatcache2, copy, dirname, 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, preg_match, preg_replace, preg_replace_callback, rename, rmdir, rtrim, str_repeat,
- str_replace, strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch, unlink,
- usleep, var_export,
+ php_regex, preg_is_match, preg_match, preg_replace, preg_replace_callback, rename, rmdir,
+ rtrim, str_repeat, str_replace, strlen, strpos, strtoupper, strtr, substr, substr_count,
+ symlink, touch, unlink, usleep, var_export,
};
use shirabe_symfony_filesystem::exception::IOException;
use shirabe_symfony_finder::Finder;
@@ -246,7 +246,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if preg_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory).is_some() {
+ if preg_is_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory) {
return Err(RuntimeException::new(format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory))
.into());
}
@@ -578,7 +578,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
+ && !preg_is_match(php_regex!("{^[A-Z]:/?$}i"), &common_path)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -635,7 +635,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
+ && !preg_is_match(php_regex!("{^[A-Z]:/?$}i"), &common_path)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -778,7 +778,7 @@ impl Filesystem {
/// And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422
pub fn trim_trailing_slash(path: &str) -> String {
let mut path = path.to_string();
- if preg_match(php_regex!("{^[/\\\\]+$}"), &path).is_none() {
+ if !preg_is_match(php_regex!("{^[/\\\\]+$}"), &path) {
path = rtrim(&path, Some("/\\"));
}
@@ -790,20 +790,18 @@ impl Filesystem {
// on windows, \\foo indicates network paths so we exclude those from local paths, however it is unsafe
// on linux as file:////foo (which would be a network path \\foo on windows) will resolve to /foo which could be a local path
if Platform::is_windows() {
- return preg_match(
+ return preg_is_match(
php_regex!(
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"
),
path,
- )
- .is_some();
+ );
}
- preg_match(
+ preg_is_match(
php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"),
path,
)
- .is_some()
}
pub fn get_platform_path(path: &str) -> String {