win32/rmdir_r.cpp: Try with RemoveDirectory
All checks were successful
/ build (pull_request) Successful in 13m5s

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
This commit is contained in:
Xavier Del Campo Romero 2025-01-09 21:56:40 +01:00
parent 709f34eddc
commit 87ac21db8a
Signed by: xavi
GPG key ID: 84FF3612A9BF43F2

View file

@ -68,8 +68,15 @@ int portability::rmdir_r(const char *path)
if ((res = SHFileOperation(&op))) if ((res = SHFileOperation(&op)))
{ {
fprintf(stderr, "%s: SHFileOperation failed with %#x\n", __func__, res); fprintf(stderr, "%s: SHFileOperation %s failed with %#x, "
goto end; "trying with RemoveDirectory\n", __func__, path, res);
if (!RemoveDirectory(path))
{
fprintf(stderr, "%s: RemoveDirectory %s failed with %#jx\n",
__func__, path, static_cast<intmax_t>(GetLastError()));
goto end;
}
} }
else if (op.fAnyOperationsAborted) else if (op.fAnyOperationsAborted)
{ {