Zebediah Figura : msi: Only delete empty registry keys in delete_key().

Alexandre Julliard julliard at winehq.org
Tue Jun 5 17:06:41 CDT 2018


Module: wine
Branch: master
Commit: 91e418073f64368110a9339d17fad36ad26c1a7f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=91e418073f64368110a9339d17fad36ad26c1a7f

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Fri Jun  1 21:48:20 2018 -0500

msi: Only delete empty registry keys in delete_key().

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msi/action.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/dlls/msi/action.c b/dlls/msi/action.c
index 7197bca..ddd676d 100644
--- a/dlls/msi/action.c
+++ b/dlls/msi/action.c
@@ -2981,12 +2981,27 @@ static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
     return rc;
 }
 
+static int is_key_empty(const MSICOMPONENT *comp, HKEY root, const WCHAR *path)
+{
+    DWORD subkeys, values;
+    HKEY key;
+    LONG res;
+
+    key = open_key(comp, root, path, FALSE, get_registry_view(comp) | KEY_READ);
+    if (!key) return 0;
+
+    res = RegQueryInfoKeyW(key, 0, 0, 0, &subkeys, 0, 0, &values, 0, 0, 0, 0);
+    RegCloseKey(key);
+
+    return !res && !subkeys && !values;
+}
+
 static void delete_key( const MSICOMPONENT *comp, HKEY root, const WCHAR *path )
 {
+    LONG res = ERROR_SUCCESS;
     REGSAM access = 0;
     WCHAR *subkey, *p;
     HKEY hkey;
-    LONG res;
 
     access |= get_registry_view( comp );
 
@@ -2999,10 +3014,15 @@ static void delete_key( const MSICOMPONENT *comp, HKEY root, const WCHAR *path )
             if (!p[1]) continue; /* trailing backslash */
             hkey = open_key( comp, root, subkey, FALSE, access | READ_CONTROL );
             if (!hkey) break;
+            if (!is_key_empty(comp, hkey, p + 1))
+            {
+                RegCloseKey(hkey);
+                break;
+            }
             res = RegDeleteKeyExW( hkey, p + 1, access, 0 );
             RegCloseKey( hkey );
         }
-        else
+        else if (is_key_empty(comp, root, subkey))
             res = RegDeleteKeyExW( root, subkey, access, 0 );
         if (res)
         {
@@ -3017,17 +3037,14 @@ static void delete_value( const MSICOMPONENT *comp, HKEY root, const WCHAR *path
 {
     LONG res;
     HKEY hkey;
-    DWORD num_subkeys, num_values;
 
     if ((hkey = open_key( comp, root, path, FALSE, KEY_SET_VALUE | KEY_QUERY_VALUE )))
     {
         if ((res = RegDeleteValueW( hkey, value )))
             TRACE("failed to delete value %s (%d)\n", debugstr_w(value), res);
 
-        res = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, &num_subkeys, NULL, NULL, &num_values,
-                                NULL, NULL, NULL, NULL );
         RegCloseKey( hkey );
-        if (!res && !num_subkeys && !num_values)
+        if (is_key_empty(comp, root, path))
         {
             TRACE("removing empty key %s\n", debugstr_w(path));
             delete_key( comp, root, path );




More information about the wine-cvs mailing list