Fixes a bug where `rundll32.exe advpack.dll,DelNodeRunDLL32 "c:\test",1` is only supposed to delete "test" if the directory is empty.
Also causes the [DelDirs Inf section](https://www.mdgx.com/INF_web/deldirs.htm) to work correctly.
Notes: - I changed the code so it ignores the result of `SetFileAttributesW` because the user might not have FILE_WRITE_ATTRIBUTES even if they have DELETE rights. This seems to match Windows (XP NTFS).
From: anders andersdev@proton.me
--- dlls/advpack/files.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/dlls/advpack/files.c b/dlls/advpack/files.c index 2bf2481cca4..fa247cb3f07 100644 --- a/dlls/advpack/files.c +++ b/dlls/advpack/files.c @@ -320,6 +320,9 @@ static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags) BOOL done = TRUE; int fname_len = lstrlenW(fname);
+ if (flags & ADN_DEL_IF_EMPTY) + goto onlyemptydir; + /* Generate a path with wildcard suitable for iterating */ if (fname_len && fname[fname_len-1] != '\') fname[fname_len++] = '\'; lstrcpyW(fname + fname_len, L"*"); @@ -347,8 +350,10 @@ static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags)
if (done) { +onlyemptydir: TRACE("%s: directory\n", debugstr_w(fname)); - if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryW(fname)) + SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL); + if (RemoveDirectoryW(fname)) { ret = S_OK; } @@ -357,7 +362,8 @@ static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags) else { TRACE("%s: file\n", debugstr_w(fname)); - if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileW(fname)) + SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL); + if (DeleteFileW(fname)) { ret = S_OK; }
Can some tests be added for this flag?