From d4d6cec52da8fffbab5635af6d0149a10a59dcb6 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 2 Oct 2022 11:08:53 +0300 Subject: [PATCH] Ticket #4364: FISH VFS: cannot remove non-empty directory. Revert "(check_dir_is_empty): minor optimization." This reverts commit 25e419ba0886f1a046ddcca7d9dd9fb7ddd16998. Signed-off-by: Andrew Borodin --- src/filemanager/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 17d64fe54..119ecf380 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1484,19 +1484,21 @@ check_dir_is_empty (const vfs_path_t * vpath) { DIR *dir; struct vfs_dirent *d; - int i = 0; + int i = 1; dir = mc_opendir (vpath); if (dir == NULL) return -1; - /* https://stackoverflow.com/questions/6383584/check-if-a-directory-is-empty-using-c-on-linux */ - while ((d = mc_readdir (dir)) != NULL) - if (++i > 2) + for (d = mc_readdir (dir); d != NULL; d = mc_readdir (dir)) + if (!DIR_IS_DOT (d->d_name) && !DIR_IS_DOTDOT (d->d_name)) + { + i = 0; break; + } mc_closedir (dir); - return i <= 2 ? 1 : 0; + return i; } /* --------------------------------------------------------------------------------------------- */