aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs12
-rw-r--r--crates/shirabe-php-shim/src/fs.rs24
-rw-r--r--crates/shirabe/src/cache.rs3
-rw-r--r--crates/shirabe/src/console/application.rs2
-rw-r--r--crates/shirabe/src/factory.rs2
-rw-r--r--crates/shirabe/src/json/json_file.rs2
-rw-r--r--crates/shirabe/src/util/filesystem.rs14
-rw-r--r--crates/shirabe/tests/autoload/autoload_generator_test.rs4
-rw-r--r--crates/shirabe/tests/util/filesystem_test.rs4
9 files changed, 26 insertions, 41 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs b/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs
index 450c7191..a0142ce6 100644
--- a/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs
+++ b/crates/shirabe-external-packages/src/symfony/filesystem/filesystem.rs
@@ -146,7 +146,7 @@ impl Filesystem {
continue;
}
- if let Err(last_error) = shirabe_php_shim::mkdir_result(&dir, mode, true)
+ if let Err(last_error) = shirabe_php_shim::mkdir(&dir, mode, true)
&& !shirabe_php_shim::is_dir(&dir)
{
return Err(IOException::new(
@@ -202,11 +202,11 @@ impl Filesystem {
for file in files {
if shirabe_php_shim::is_link(&file) {
// See https://bugs.php.net/52176
- let unlinked = shirabe_php_shim::unlink_result(&file);
+ let unlinked = shirabe_php_shim::unlink(&file);
let mut last_error = unlinked.as_ref().err().map(ToString::to_string);
let mut removed = unlinked.is_ok() || !cfg!(windows);
if !removed {
- match shirabe_php_shim::rmdir_result(&file) {
+ match shirabe_php_shim::rmdir(&file) {
Ok(()) => {
last_error = None;
removed = true;
@@ -251,7 +251,7 @@ impl Filesystem {
(&entries).into_iter().map(|e| e.get_pathname()).collect();
Self::do_remove(child_paths, true)?;
- if let Err(last_error) = shirabe_php_shim::rmdir_result(&file)
+ if let Err(last_error) = shirabe_php_shim::rmdir(&file)
&& shirabe_php_shim::file_exists(&file)
{
return Err(IOException::new(
@@ -262,7 +262,7 @@ impl Filesystem {
)
.into());
}
- } else if let Err(last_error) = shirabe_php_shim::unlink_result(&file) {
+ } else if let Err(last_error) = shirabe_php_shim::unlink(&file) {
let last_error = last_error.to_string();
if last_error.contains("Permission denied") || shirabe_php_shim::file_exists(&file)
{
@@ -309,7 +309,7 @@ impl Filesystem {
self.remove(PhpMixed::String(target_dir.clone()))?;
}
- if let Err(last_error) = shirabe_php_shim::symlink_result(&origin_dir, &target_dir) {
+ if let Err(last_error) = shirabe_php_shim::symlink(&origin_dir, &target_dir) {
return Self::link_exception(
&origin_dir,
&target_dir,
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index eae41dda..bd5e650a 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -834,11 +834,7 @@ pub fn filemtime(_filename: impl AsRef<std::path::Path>) -> Option<i64> {
.map(|d| d.as_secs() as i64)
}
-pub fn unlink(path: impl AsRef<std::path::Path>) -> bool {
- unlink_result(path).is_ok()
-}
-
-pub fn unlink_result(path: impl AsRef<std::path::Path>) -> Result<(), std::io::Error> {
+pub fn unlink(path: impl AsRef<std::path::Path>) -> Result<(), std::io::Error> {
std::fs::remove_file(path)
}
@@ -968,11 +964,7 @@ pub fn umask() -> u32 {
previous.bits() as u32
}
-pub fn mkdir(_pathname: impl AsRef<std::path::Path>, _mode: u32, _recursive: bool) -> bool {
- mkdir_result(_pathname, _mode, _recursive).is_ok()
-}
-
-pub fn mkdir_result(
+pub fn mkdir(
pathname: impl AsRef<std::path::Path>,
mode: u32,
recursive: bool,
@@ -984,11 +976,7 @@ pub fn mkdir_result(
builder.create(pathname.as_ref())
}
-pub fn rmdir(dir: impl AsRef<std::path::Path>) -> bool {
- rmdir_result(dir).is_ok()
-}
-
-pub fn rmdir_result(dir: impl AsRef<std::path::Path>) -> Result<(), std::io::Error> {
+pub fn rmdir(dir: impl AsRef<std::path::Path>) -> Result<(), std::io::Error> {
std::fs::remove_dir(dir)
}
@@ -1029,11 +1017,7 @@ pub fn ftruncate(stream: &PhpResource, size: i64) -> bool {
}
}
-pub fn symlink(_target: impl AsRef<std::path::Path>, _link: impl AsRef<std::path::Path>) -> bool {
- symlink_result(_target, _link).is_ok()
-}
-
-pub fn symlink_result(
+pub fn symlink(
target: impl AsRef<std::path::Path>,
link: impl AsRef<std::path::Path>,
) -> Result<(), std::io::Error> {
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs
index a9f56eac..14f7287f 100644
--- a/crates/shirabe/src/cache.rs
+++ b/crates/shirabe/src/cache.rs
@@ -106,7 +106,8 @@ impl Cache {
if !self.read_only
&& ((!is_dir(&self.root)
- && !Silencer::call(|| Ok(mkdir(&self.root, 0o777, true))).unwrap_or(false))
+ && !Silencer::call(|| Ok(mkdir(&self.root, 0o777, true).is_ok()))
+ .unwrap_or(false))
|| !is_writable(&self.root))
{
self.io.write_error(&format!(
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index bf1f3575..05cd1d22 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -2335,7 +2335,7 @@ impl ApplicationHandle {
);
if !(file_put_contents(&tempfile, file!().as_bytes()).is_some_and(|n| n > 0)
&& file_get_contents(&tempfile).as_deref() == Some(file!())
- && unlink(&tempfile)
+ && unlink(&tempfile).is_ok()
&& !file_exists(&tempfile))
{
return Ok(Some(format!("<error>PHP temp directory ({}) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini</error>", sys_get_temp_dir())));
diff --git a/crates/shirabe/src/factory.rs b/crates/shirabe/src/factory.rs
index d7439d58..18ff8ef5 100644
--- a/crates/shirabe/src/factory.rs
+++ b/crates/shirabe/src/factory.rs
@@ -299,7 +299,7 @@ impl Factory {
if !is_dir(dir) {
let dir_owned = dir.clone();
let _ = Silencer::call(|| {
- Ok::<bool, anyhow::Error>(mkdir(&dir_owned, 0o777, true))
+ Ok::<bool, anyhow::Error>(mkdir(&dir_owned, 0o777, true).is_ok())
});
}
let path = format!("{}/.htaccess", dir);
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index feb72764..4c74b83e 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -237,7 +237,7 @@ impl JsonFile {
.into());
}
// PHP: @mkdir($dir, 0777, true)
- if !Silencer::call(|| Ok(mkdir(&dir, 0o777, true))).unwrap_or(false) {
+ if !Silencer::call(|| Ok(mkdir(&dir, 0o777, true).is_ok())).unwrap_or(false) {
return Err(UnexpectedValueException::new(format!(
"{} does not exist and could not be created.",
dir
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 2c4cbcc6..925cb38a 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -240,7 +240,7 @@ impl Filesystem {
}
if is_link(directory) {
- return Ok(Some(unlink(directory)));
+ return Ok(Some(unlink(directory).is_ok()));
}
if !is_dir(directory) || !file_exists(directory) {
@@ -328,7 +328,7 @@ impl Filesystem {
.into());
}
- if !mkdir(directory, 0o777, true) {
+ if mkdir(directory, 0o777, true).is_err() {
let e = RuntimeException::new(format!(
"{} does not exist and could not be created: {}",
directory,
@@ -393,12 +393,12 @@ impl Filesystem {
/// Attempts to rmdir a file and in case of failure retries after 350ms on windows
pub fn rmdir(&self, path: impl AsRef<Path>) -> anyhow::Result<bool> {
let path = path.as_ref();
- let mut deleted = rmdir(path);
+ let mut deleted = rmdir(path).is_ok();
if !deleted {
// retry after a bit on windows since it tends to be touchy with mass removals
if Platform::is_windows() {
usleep(350000);
- deleted = rmdir(path);
+ deleted = rmdir(path).is_ok();
}
if !deleted {
@@ -922,10 +922,10 @@ impl Filesystem {
/// symbolic links on windows which link to directories need rmdir instead of unlink
fn unlink_implementation(&self, path: &Path) -> bool {
if Platform::is_windows() && is_dir(path) && is_link(path) {
- return rmdir(path);
+ return rmdir(path).is_ok();
}
- unlink(path)
+ unlink(path).is_ok()
}
/// Creates a relative symlink from $link to $target
@@ -938,7 +938,7 @@ impl Filesystem {
let relative_path = self.find_shortest_path(link, target, false, false);
chdir(dirname(link));
- let result = symlink(&relative_path, link);
+ let result = symlink(&relative_path, link).is_ok();
chdir(&cwd);
diff --git a/crates/shirabe/tests/autoload/autoload_generator_test.rs b/crates/shirabe/tests/autoload/autoload_generator_test.rs
index 97fabf16..81a4040f 100644
--- a/crates/shirabe/tests/autoload/autoload_generator_test.rs
+++ b/crates/shirabe/tests/autoload/autoload_generator_test.rs
@@ -2535,7 +2535,7 @@ fn test_absolute_symlink_with_psr4_does_not_generate_warnings() {
// Create an absolute symlink
let target = format!("{}/tools-real", s.working_dir);
let r#link = format!("{}/tools", s.working_dir);
- assert!(shirabe_php_shim::symlink(&target, &r#link));
+ assert!(shirabe_php_shim::symlink(&target, &r#link).is_ok());
package.set_autoload(autoload(vec![
("psr-4", str_map(&[("MyTools\\", pstr("tools/"))])),
@@ -2577,7 +2577,7 @@ fn test_absolute_symlink_with_classmap_exclude_from_classmap() {
// Create an absolute symlink
let target = format!("{}/tools-real", s.working_dir);
let r#link = format!("{}/tools", s.working_dir);
- assert!(shirabe_php_shim::symlink(&target, &r#link));
+ assert!(shirabe_php_shim::symlink(&target, &r#link).is_ok());
package.set_autoload(autoload(vec![
("classmap", str_list(&["tools/"])),
diff --git a/crates/shirabe/tests/util/filesystem_test.rs b/crates/shirabe/tests/util/filesystem_test.rs
index 5bb44598..b217a342 100644
--- a/crates/shirabe/tests/util/filesystem_test.rs
+++ b/crates/shirabe/tests/util/filesystem_test.rs
@@ -512,7 +512,7 @@ fn test_unlink_symlinked_directory() {
mkdir(format!("{basepath}/real"), 0o777, true);
touch(format!("{basepath}/real/FILE"));
- let result = symlink(format!("{basepath}/real"), &symlinked);
+ let result = symlink(format!("{basepath}/real"), &symlinked).is_ok();
if !result {
// Symbolic links for directories not supported on this platform.
@@ -539,7 +539,7 @@ fn test_remove_symlinked_directory_with_trailing_slash() {
let symlinked = format!("{working_dir}/linked");
let symlinked_trailing_slash = format!("{symlinked}/");
- let result = symlink(format!("{working_dir}/real"), &symlinked);
+ let result = symlink(format!("{working_dir}/real"), &symlinked).is_ok();
if !result {
// Symbolic links for directories not supported on this platform.