Commit 5d37be9e authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

msi: Only remove a file if the version to be installed is strictly newer than the old file.

parent 6ca62033
......@@ -823,6 +823,24 @@ UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
return rc;
}
/* compares the version of a file read from the filesystem and
* the version specified in the File table
*/
static int msi_compare_file_version( MSIFILE *file )
{
WCHAR version[MAX_PATH];
DWORD size;
UINT r;
size = MAX_PATH;
version[0] = '\0';
r = MsiGetFileVersionW( file->TargetPath, version, &size, NULL, NULL );
if ( r != ERROR_SUCCESS )
return 0;
return lstrcmpW( version, file->Version );
}
UINT ACTION_RemoveFiles( MSIPACKAGE *package )
{
MSIFILE *file;
......@@ -843,6 +861,12 @@ UINT ACTION_RemoveFiles( MSIPACKAGE *package )
if ( file->state != msifs_present )
continue;
/* only remove a file if the version to be installed
* is strictly newer than the old file
*/
if ( msi_compare_file_version( file ) >= 0 )
continue;
TRACE("removing %s\n", debugstr_w(file->File) );
if ( !DeleteFileW( file->TargetPath ) )
ERR("failed to delete %s\n", debugstr_w(file->TargetPath) );
......
......@@ -1938,13 +1938,10 @@ static void test_removefiles(void)
r = MsiDoAction( hpkg, "RemoveFiles");
ok( r == ERROR_SUCCESS, "remove files failed\n");
todo_wine
{
ok(DeleteFileA("hydrogen.txt"), "Expected hydrogen.txt to exist\n");
ok(DeleteFileA("lithium.txt"), "Expected lithium.txt to exist\n");
ok(DeleteFileA("beryllium.txt"), "Expected beryllium.txt to exist\n");
ok(DeleteFileA("carbon.txt"), "Expected carbon.txt to exist\n");
}
ok(DeleteFileA("hydrogen.txt"), "Expected hydrogen.txt to exist\n");
ok(DeleteFileA("lithium.txt"), "Expected lithium.txt to exist\n");
ok(DeleteFileA("beryllium.txt"), "Expected beryllium.txt to exist\n");
ok(DeleteFileA("carbon.txt"), "Expected carbon.txt to exist\n");
ok(DeleteFileA("helium.txt"), "Expected helium.txt to exist\n");
ok(DeleteFileA("boron.txt"), "Expected boron.txt to exist\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment