msi: Fix download of installer packages. Return errors from msi_download_file and copy_package_to_temp.

This commit is contained in:
Hans Leidekker 2009-12-17 12:28:49 +01:00 committed by Alexandre Julliard
parent 4e7389e44b
commit ff2aa7e3a6
2 changed files with 34 additions and 16 deletions

View File

@ -757,7 +757,7 @@ extern MSICONDITION MSI_EvaluateConditionW( MSIPACKAGE *, LPCWSTR );
extern UINT MSI_GetComponentStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * ); extern UINT MSI_GetComponentStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * );
extern UINT MSI_GetFeatureStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * ); extern UINT MSI_GetFeatureStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * );
extern UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE*, LPCWSTR, INSTALLSTATE ); extern UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE*, LPCWSTR, INSTALLSTATE );
extern LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename ); extern UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename );
extern UINT msi_package_add_info(MSIPACKAGE *, DWORD, DWORD, LPCWSTR, LPWSTR); extern UINT msi_package_add_info(MSIPACKAGE *, DWORD, DWORD, LPCWSTR, LPWSTR);
extern UINT msi_package_add_media_disk(MSIPACKAGE *, DWORD, DWORD, DWORD, LPWSTR, LPWSTR); extern UINT msi_package_add_media_disk(MSIPACKAGE *, DWORD, DWORD, DWORD, LPWSTR, LPWSTR);
extern UINT msi_clone_properties(MSIPACKAGE *); extern UINT msi_clone_properties(MSIPACKAGE *);

View File

@ -833,7 +833,7 @@ MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
* we should read all the tables to memory, then open the * we should read all the tables to memory, then open the
* database to read binary streams on demand. * database to read binary streams on demand.
*/ */
static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename ) static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
{ {
WCHAR path[MAX_PATH]; WCHAR path[MAX_PATH];
@ -842,16 +842,16 @@ static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
if( !CopyFileW( szPackage, filename, FALSE ) ) if( !CopyFileW( szPackage, filename, FALSE ) )
{ {
UINT error = GetLastError();
ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
DeleteFileW( filename ); DeleteFileW( filename );
ERR("failed to copy package %s\n", debugstr_w(szPackage) ); return error;
return szPackage;
} }
TRACE("Opening relocated package %s\n", debugstr_w( filename )); return ERROR_SUCCESS;
return filename;
} }
LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename ) UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
{ {
LPINTERNET_CACHE_ENTRY_INFOW cache_entry; LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
DWORD size = 0; DWORD size = 0;
@ -867,20 +867,24 @@ LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
cache_entry = HeapAlloc( GetProcessHeap(), 0, size ); cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) ) if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
{ {
UINT error = GetLastError();
HeapFree( GetProcessHeap(), 0, cache_entry ); HeapFree( GetProcessHeap(), 0, cache_entry );
return szUrl; return error;
} }
lstrcpyW( filename, cache_entry->lpszLocalFileName ); lstrcpyW( filename, cache_entry->lpszLocalFileName );
HeapFree( GetProcessHeap(), 0, cache_entry ); HeapFree( GetProcessHeap(), 0, cache_entry );
return filename; return ERROR_SUCCESS;
} }
hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL ); hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
if ( FAILED(hr) ) if ( FAILED(hr) )
return szUrl; {
WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
return ERROR_FUNCTION_FAILED;
}
return filename; return ERROR_SUCCESS;
} }
static UINT msi_get_local_package_name( LPWSTR path ) static UINT msi_get_local_package_name( LPWSTR path )
@ -925,7 +929,7 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
MSIHANDLE handle; MSIHANDLE handle;
LPWSTR ptr, base_url = NULL; LPWSTR ptr, base_url = NULL;
UINT r; UINT r;
WCHAR temppath[MAX_PATH], localfile[MAX_PATH]; WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
LPCWSTR file = szPackage; LPCWSTR file = szPackage;
TRACE("%s %p\n", debugstr_w(szPackage), pPackage); TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
@ -952,9 +956,15 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
{ {
if ( UrlIsW( szPackage, URLIS_URL ) ) if ( UrlIsW( szPackage, URLIS_URL ) )
{ {
file = msi_download_file( szPackage, temppath ); r = msi_download_file( szPackage, cachefile );
if ( file != szPackage ) if ( r != ERROR_SUCCESS )
file = copy_package_to_temp( file, temppath ); return r;
r = copy_package_to_temp( cachefile, temppath );
if ( r != ERROR_SUCCESS )
return r;
file = temppath;
base_url = strdupW( szPackage ); base_url = strdupW( szPackage );
if ( !base_url ) if ( !base_url )
@ -964,7 +974,13 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
if (ptr) *(ptr + 1) = '\0'; if (ptr) *(ptr + 1) = '\0';
} }
else else
file = copy_package_to_temp( szPackage, temppath ); {
r = copy_package_to_temp( szPackage, temppath );
if ( r != ERROR_SUCCESS )
return r;
file = temppath;
}
r = msi_get_local_package_name( localfile ); r = msi_get_local_package_name( localfile );
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
@ -979,6 +995,8 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
return GetLastError(); return GetLastError();
} }
TRACE("Opening relocated package %s\n", debugstr_w( file ));
/* transforms that add binary streams require that we open the database /* transforms that add binary streams require that we open the database
* read/write, which is safe because we always create a copy that is thrown * read/write, which is safe because we always create a copy that is thrown
* away when we're done. * away when we're done.