From f1cd7e1d9dfacae6361a51d9e8e64744491874ee Mon Sep 17 00:00:00 2001 From: Ajabep Date: Thu, 29 Jun 2023 19:37:28 +0200 Subject: [PATCH] Fix a bug in the recursive rmdir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A directory containing a directory containing files where never deleted. Example: Let's consider this configuration: ``` /tmp/root └── intermediate ├── file1 ├── file2 └── file3 ``` This configuration was able to occured during a plugin update. If NC was running a `rmdirr("/tmp/root");` (which seems to be done during a cron, but, that's not important), it would never deleted anything. Indeed, the `$files` variable would contians only the `intermediate` directory. Thus, during the loop to delete the content of the `/tmp/root` content, when `$fileInfo` will contains the descriptor of `/tmp/root/intermediate`, the `rmdir` PHP function would fails because this directory is not empty.... And maked the final `rmdir` (in the `$deleteSelf` condition). Tested on `PHP 8.1.20 (built: Jun 15 2023 01:23:25) (NTS)`, the PHP version of the docker container provided by NC-AIO. Signed-off-by: Ajabep --- lib/private/legacy/OC_Helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 8c8be0e1069d0..7bffbabce295f 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -173,7 +173,7 @@ public static function rmdirr($dir, $deleteSelf = true) { if ($fileInfo->isLink()) { unlink($fileInfo->getPathname()); } elseif ($fileInfo->isDir()) { - rmdir($fileInfo->getRealPath()); + self::rmdirr($fileInfo->getRealPath()); } else { unlink($fileInfo->getRealPath()); }