msi: Don't cache the base URL.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2018-04-18 10:05:46 +02:00 committed by Alexandre Julliard
parent 1b88ec9c7a
commit 99aa0eb5d8
4 changed files with 35 additions and 35 deletions

View File

@ -4113,7 +4113,7 @@ static MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE *db )
MSIPREVIEW *preview = NULL;
MSIPACKAGE *package;
package = MSI_CreatePackage( db, NULL );
package = MSI_CreatePackage( db );
if (package)
{
preview = alloc_msiobject( MSIHANDLETYPE_PREVIEW, sizeof(MSIPREVIEW), MSI_ClosePreview );

View File

@ -678,6 +678,14 @@ static UINT get_drive_type(const WCHAR *path)
return GetDriveTypeW(root);
}
static WCHAR *get_base_url( MSIDATABASE *db )
{
WCHAR *p, *ret = NULL, *orig_db = msi_dup_property( db, szOriginalDatabase );
if (UrlIsW( orig_db, URLIS_URL ) && (ret = strdupW( orig_db )) && (p = strrchrW( ret, '/'))) p[1] = 0;
msi_free( orig_db );
return ret;
}
UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
{
static const WCHAR query[] = {
@ -685,7 +693,7 @@ UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
'>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
MSIRECORD *row;
LPWSTR source_dir, source;
WCHAR *source_dir, *source, *base_url = NULL;
DWORD options;
if (Sequence <= mi->last_sequence) /* already loaded */
@ -721,9 +729,9 @@ UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
source = source_dir;
options |= MSISOURCETYPE_MEDIA;
}
else if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
else if ((base_url = get_base_url(package->db)))
{
source = package->BaseURL;
source = base_url;
options |= MSISOURCETYPE_URL;
}
else
@ -739,8 +747,10 @@ UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
msi_package_add_info(package, package->Context,
options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
msi_free(source_dir);
TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence, debugstr_w(mi->cabinet), mi->disk_id);
msi_free(base_url);
msi_free(source_dir);
return ERROR_SUCCESS;
}
@ -851,6 +861,8 @@ UINT ready_media( MSIPACKAGE *package, BOOL compressed, MSIMEDIAINFO *mi )
if (mi->cabinet)
{
WCHAR *base_url;
/* cabinet is internal, no checks needed */
if (mi->cabinet[0] == '#') return ERROR_SUCCESS;
@ -858,14 +870,21 @@ UINT ready_media( MSIPACKAGE *package, BOOL compressed, MSIMEDIAINFO *mi )
/* package should be downloaded */
if (compressed && GetFileAttributesW( cabinet_file ) == INVALID_FILE_ATTRIBUTES &&
package->BaseURL && UrlIsW( package->BaseURL, URLIS_URL ))
(base_url = get_base_url( package->db )))
{
WCHAR temppath[MAX_PATH], *p;
WCHAR temppath[MAX_PATH], *p, *url;
if ((rc = msi_download_file( cabinet_file, temppath )) != ERROR_SUCCESS)
msi_free( cabinet_file );
if (!(url = msi_alloc( (strlenW( base_url ) + strlenW( mi->cabinet ) + 1) * sizeof(WCHAR) )))
{
ERR("failed to download %s (%u)\n", debugstr_w(cabinet_file), rc);
msi_free( cabinet_file );
return ERROR_OUTOFMEMORY;
}
strcpyW( url, base_url );
strcatW( url, mi->cabinet );
if ((rc = msi_download_file( url, temppath )) != ERROR_SUCCESS)
{
ERR("failed to download %s (%u)\n", debugstr_w(url), rc);
msi_free( url );
return rc;
}
if ((p = strrchrW( temppath, '\\' ))) *p = 0;
@ -873,7 +892,8 @@ UINT ready_media( MSIPACKAGE *package, BOOL compressed, MSIMEDIAINFO *mi )
PathAddBackslashW( mi->sourcedir );
msi_free( mi->cabinet );
mi->cabinet = strdupW( p + 1 );
msi_free( cabinet_file );
msi_free( url );
return ERROR_SUCCESS;
}
}

View File

@ -424,7 +424,6 @@ typedef struct tagMSIPACKAGE
struct list RunningActions;
LPWSTR BaseURL;
LPWSTR PackagePath;
LPWSTR ProductCode;
LPWSTR localfile;
@ -861,7 +860,7 @@ extern UINT msi_view_get_row(MSIDATABASE *, MSIVIEW *, UINT, MSIRECORD **) DECLS
extern UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel ) DECLSPEC_HIDDEN;
/* package internals */
extern MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *, LPCWSTR ) DECLSPEC_HIDDEN;
extern MSIPACKAGE *MSI_CreatePackage( MSIDATABASE * ) DECLSPEC_HIDDEN;
extern UINT MSI_OpenPackageW( LPCWSTR szPackage, MSIPACKAGE **pPackage ) DECLSPEC_HIDDEN;
extern UINT MSI_SetTargetPathW( MSIPACKAGE *, LPCWSTR, LPCWSTR ) DECLSPEC_HIDDEN;
extern INT MSI_ProcessMessageVerbatim( MSIPACKAGE *, INSTALLMESSAGE, MSIRECORD * ) DECLSPEC_HIDDEN;

View File

@ -321,7 +321,6 @@ static void free_package_structures( MSIPACKAGE *package )
msi_free_patchinfo( patch );
}
msi_free( package->BaseURL );
msi_free( package->PackagePath );
msi_free( package->ProductCode );
msi_free( package->ActionFormat );
@ -1056,7 +1055,7 @@ void msi_adjust_privilege_properties( MSIPACKAGE *package )
msi_set_property( package->db, szAdminUser, szOne, -1 );
}
MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
{
static const WCHAR fmtW[] = {'%','u',0};
MSIPACKAGE *package;
@ -1077,7 +1076,6 @@ MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
package->LastActionResult = MSI_NULL_INTEGER;
package->WordCount = 0;
package->PackagePath = strdupW( db->path );
package->BaseURL = strdupW( base_url );
create_temp_property_table( package );
msi_clone_properties( package->db );
@ -1447,15 +1445,13 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
MSIPACKAGE *package;
MSIHANDLE handle;
MSIRECORD *data_row, *info_row;
LPWSTR ptr, base_url = NULL;
UINT r;
WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
LPCWSTR file = szPackage;
DWORD index = 0;
MSISUMMARYINFO *si;
BOOL delete_on_close = FALSE;
LPWSTR productname;
WCHAR *info_template;
WCHAR *info_template, *productname;
TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
@ -1487,30 +1483,19 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
return r;
file = cachefile;
base_url = strdupW( szPackage );
if (!base_url)
return ERROR_OUTOFMEMORY;
ptr = strrchrW( base_url, '/' );
if (ptr) *(ptr + 1) = '\0';
}
r = get_local_package( file, localfile );
if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
{
r = msi_create_empty_local_file( localfile, dotmsi );
if (r != ERROR_SUCCESS)
{
msi_free ( base_url );
return r;
}
if (!CopyFileW( file, localfile, FALSE ))
{
r = GetLastError();
WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
DeleteFileW( localfile );
msi_free ( base_url );
return r;
}
delete_on_close = TRUE;
@ -1518,13 +1503,9 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
TRACE("opening package %s\n", debugstr_w( localfile ));
r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
if (r != ERROR_SUCCESS)
{
msi_free ( base_url );
return r;
}
}
package = MSI_CreatePackage( db, base_url );
msi_free( base_url );
package = MSI_CreatePackage( db );
msiobj_release( &db->hdr );
if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
package->localfile = strdupW( localfile );