From 9c1d02f30cbf52945242a3ed6a12abb153dd0298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Thu, 17 Oct 2024 00:16:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extend/ToolsExtend.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/extend/ToolsExtend.php b/src/extend/ToolsExtend.php index 50af9912..01d441c6 100644 --- a/src/extend/ToolsExtend.php +++ b/src/extend/ToolsExtend.php @@ -71,10 +71,15 @@ public static function copyfile(string $frdir, string $todir, array $files = [], */ public static function removeEmptyDirectory(string $path): bool { - foreach (self::findFilesYield($path, null, null, true) as $item) { - ($item->isFile() || $item->isLink()) ? unlink($item->getPathname()) : rmdir($item->getPathname()); - } - return is_file($path) ? unlink($path) : (!is_dir($path) || rmdir($path)); + $dirs = [$path]; + iterator_to_array(self::findFilesYield($path, null, function (SplFileInfo $file) use (&$dirs) { + $file->isDir() ? $dirs[] = $file->getPathname() : unlink($file->getPathname()); + })); + usort($dirs, function ($a, $b) { + return strlen($b) <=> strlen($a); + }); + foreach ($dirs as $dir) rmdir($dir); + return !file_exists($path); } /**