[ADVPACK] Handle ADN_DEL_IF_EMPTY in DelNodeW and DelNodeRunDLL32 (#5821)

- Handling ADN_DEL_IF_EMPTY is critical to avoid data loss.
- SetFileAttributesW failing is not fatal, the delete might still succeed.

NOTE: Not in Wine yet.
This commit is contained in:
Whindmar Saksit 2023-11-13 16:42:26 +01:00 committed by GitHub
parent f283a3f9ae
commit 6eb8a1d0c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -341,9 +341,17 @@ static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags)
HANDLE hFindFile;
WIN32_FIND_DATAW w32fd;
BOOL done = TRUE;
int fname_len = lstrlenW(fname);
int fname_len;
#ifdef __REACTOS__
if (flags & ADN_DEL_IF_EMPTY)
{
goto deleteinitialdirectory;
}
#endif
/* Generate a path with wildcard suitable for iterating */
fname_len = lstrlenW(fname);
if (fname_len && fname[fname_len-1] != '\\') fname[fname_len++] = '\\';
lstrcpyW(fname + fname_len, asterisk);
@ -371,8 +379,14 @@ static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags)
if (done)
{
#ifdef __REACTOS__
deleteinitialdirectory:
TRACE("%s: directory\n", debugstr_w(fname));
SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL);
if (RemoveDirectoryW(fname))
#else
if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryW(fname))
#endif
{
ret = S_OK;
}
@ -381,7 +395,12 @@ static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags)
else
{
TRACE("%s: file\n", debugstr_w(fname));
#ifdef __REACTOS__
SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL);
if (DeleteFileW(fname))
#else
if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileW(fname))
#endif
{
ret = S_OK;
}
@ -435,9 +454,14 @@ HRESULT WINAPI DelNodeW(LPCWSTR pszFileOrDirName, DWORD dwFlags)
HRESULT ret = E_FAIL;
TRACE("(%s, %d)\n", debugstr_w(pszFileOrDirName), dwFlags);
#ifdef __REACTOS__
if (dwFlags & ~ADN_DEL_IF_EMPTY)
FIXME("Flags %#x ignored!\n", dwFlags & ~ADN_DEL_IF_EMPTY);
#else
if (dwFlags)
FIXME("Flags ignored!\n");
#endif
if (pszFileOrDirName && *pszFileOrDirName)
{