From 87ac21db8ae36ecf6e792be21a5dc31b33e859bd Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 9 Jan 2025 21:56:40 +0100 Subject: [PATCH] win32/rmdir_r.cpp: Try with RemoveDirectory SHFileOperation has been shown to fail when removing empty directories, even if the documentation does not document such behaviour. [1] Therefore, RemoveDirectoryA is used since it is meant for empty directories. [2] [1]: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shfileoperationa [2]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya --- src/libs/portability/win32/rmdir_r.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/portability/win32/rmdir_r.cpp b/src/libs/portability/win32/rmdir_r.cpp index e99a7c430..ffc70511c 100644 --- a/src/libs/portability/win32/rmdir_r.cpp +++ b/src/libs/portability/win32/rmdir_r.cpp @@ -68,8 +68,15 @@ int portability::rmdir_r(const char *path) if ((res = SHFileOperation(&op))) { - fprintf(stderr, "%s: SHFileOperation failed with %#x\n", __func__, res); - goto end; + fprintf(stderr, "%s: SHFileOperation %s failed with %#x, " + "trying with RemoveDirectory\n", __func__, path, res); + + if (!RemoveDirectory(path)) + { + fprintf(stderr, "%s: RemoveDirectory %s failed with %#jx\n", + __func__, path, static_cast(GetLastError())); + goto end; + } } else if (op.fAnyOperationsAborted) {