https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6eb8a1d0c70fcda787b9f…
commit 6eb8a1d0c70fcda787b9f16147564372bc630faf
Author: Whindmar Saksit <whindsaks(a)proton.me>
AuthorDate: Mon Nov 13 16:42:26 2023 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Nov 13 16:42:26 2023 +0100
[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.
---
dll/win32/advpack/files.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/dll/win32/advpack/files.c b/dll/win32/advpack/files.c
index 3e4cb366007..6f06bf0e9ab 100644
--- a/dll/win32/advpack/files.c
+++ b/dll/win32/advpack/files.c
@@ -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)
{