From 70e3790707cd8ba40167e443fe8a415904bd0677 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Tue, 23 Aug 2011 14:42:03 +0200 Subject: [PATCH] msi: Remove local patch packages when the product is removed. --- dlls/msi/action.c | 5 +++++ dlls/msi/msipriv.h | 3 +++ dlls/msi/package.c | 24 ++++++++++++------------ dlls/msi/patch.c | 31 +++++++++++++++++++++---------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/dlls/msi/action.c b/dlls/msi/action.c index 2c9c989fe5e..bea3052f3c6 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -4938,6 +4938,11 @@ static UINT msi_unpublish_product( MSIPACKAGE *package, const WCHAR *remove ) LIST_FOR_EACH_ENTRY(patch, &package->patches, MSIPATCHINFO, entry) { MSIREG_DeleteUserDataPatchKey(patch->patchcode, package->Context); + if (!strcmpW( package->ProductCode, patch->products )) + { + TRACE("removing local patch package %s\n", debugstr_w(patch->localfile)); + patch->delete_on_close = TRUE; + } /* FIXME: remove local patch package if this is the last product */ } TRACE("removing local package %s\n", debugstr_w(package->localfile)); diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index 7fb2d655551..2524752f0f9 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -170,10 +170,12 @@ typedef struct tagMSIPATCHINFO { struct list entry; LPWSTR patchcode; + LPWSTR products; LPWSTR transforms; LPWSTR filename; LPWSTR localfile; MSIPATCHSTATE state; + BOOL delete_on_close; } MSIPATCHINFO; typedef struct tagMSIBINARY @@ -770,6 +772,7 @@ extern UINT msi_apply_transforms( MSIPACKAGE *package ) DECLSPEC_HIDDEN; extern UINT msi_check_patch_applicable( MSIPACKAGE *package, MSISUMMARYINFO *si ) DECLSPEC_HIDDEN; extern UINT msi_apply_patches( MSIPACKAGE *package ) DECLSPEC_HIDDEN; extern UINT msi_apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code ) DECLSPEC_HIDDEN; +extern void msi_free_patchinfo( MSIPATCHINFO *patch ) DECLSPEC_HIDDEN; /* action internals */ extern UINT MSI_InstallPackage( MSIPACKAGE *, LPCWSTR, LPCWSTR ) DECLSPEC_HIDDEN; diff --git a/dlls/msi/package.c b/dlls/msi/package.c index c9cbad1800f..e6358865f83 100644 --- a/dlls/msi/package.c +++ b/dlls/msi/package.c @@ -293,18 +293,6 @@ static void free_package_structures( MSIPACKAGE *package ) msi_free( package->script ); } - LIST_FOR_EACH_SAFE( item, cursor, &package->patches ) - { - MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry ); - - list_remove( &patch->entry ); - msi_free( patch->patchcode ); - msi_free( patch->transforms ); - msi_free( patch->localfile ); - msi_free( patch->filename ); - msi_free( patch ); - } - LIST_FOR_EACH_SAFE( item, cursor, &package->binaries ) { MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry ); @@ -329,6 +317,18 @@ static void free_package_structures( MSIPACKAGE *package ) msi_free( cab ); } + LIST_FOR_EACH_SAFE( item, cursor, &package->patches ) + { + MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry ); + + list_remove( &patch->entry ); + if (patch->delete_on_close && !DeleteFileW( patch->localfile )) + { + ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError()); + } + msi_free_patchinfo( patch ); + } + msi_free( package->BaseURL ); msi_free( package->PackagePath ); msi_free( package->ProductCode ); diff --git a/dlls/msi/patch.c b/dlls/msi/patch.c index c2660adf088..4801872b32b 100644 --- a/dlls/msi/patch.c +++ b/dlls/msi/patch.c @@ -184,10 +184,16 @@ static UINT msi_parse_patch_summary( MSISUMMARYINFO *si, MSIPATCHINFO **patch ) p[1] = 0; } TRACE("patch code %s\n", debugstr_w(pi->patchcode)); - + if (!(pi->products = msi_suminfo_dup_string( si, PID_TEMPLATE ))) + { + msi_free( pi->patchcode ); + msi_free( pi ); + return ERROR_OUTOFMEMORY; + } if (!(pi->transforms = msi_suminfo_dup_string( si, PID_LASTAUTHOR ))) { msi_free( pi->patchcode ); + msi_free( pi->products ); msi_free( pi ); return ERROR_OUTOFMEMORY; } @@ -597,6 +603,16 @@ static UINT msi_apply_patch_db( MSIPACKAGE *package, MSIDATABASE *patch_db, MSIP return ERROR_SUCCESS; } +void msi_free_patchinfo( MSIPATCHINFO *patch ) +{ + msi_free( patch->patchcode ); + msi_free( patch->products ); + msi_free( patch->transforms ); + msi_free( patch->filename ); + msi_free( patch->localfile ); + msi_free( patch ); +} + static UINT msi_apply_patch_package( MSIPACKAGE *package, const WCHAR *file ) { static const WCHAR dotmsp[] = {'.','m','s','p',0}; @@ -646,11 +662,8 @@ done: msiobj_release( &patch_db->hdr ); if (patch && r != ERROR_SUCCESS) { - msi_free( patch->patchcode ); - msi_free( patch->transforms ); - msi_free( patch->filename ); - msi_free( patch->localfile ); - msi_free( patch ); + DeleteFileW( patch->localfile ); + msi_free_patchinfo( patch ); } return r; } @@ -756,6 +769,7 @@ UINT msi_apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code ) if (!patch_info->localfile) { msiobj_release( &patch_db->hdr ); + msi_free_patchinfo( patch_info ); return ERROR_OUTOFMEMORY; } r = msi_apply_patch_db( package, patch_db, patch_info ); @@ -763,10 +777,7 @@ UINT msi_apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code ) if (r != ERROR_SUCCESS) { ERR("failed to apply patch %u\n", r); - msi_free( patch_info->patchcode ); - msi_free( patch_info->transforms ); - msi_free( patch_info->localfile ); - msi_free( patch_info ); + msi_free_patchinfo( patch_info ); } return r; }