[MSI] Remove read-only bit when copying the package file 3836/head
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 12 Feb 2021 13:46:56 +0000 (14:46 +0100)
committerStanislav Motylkov <x86corez@gmail.com>
Sat, 18 Dec 2021 12:44:04 +0000 (15:44 +0300)
CopyFileW also copies the file attributes, and the copy will be opened with
write access later on.

This is import of Wine commit:
https://source.winehq.org/git/wine.git/commit/e830975806df9ef283c89f7153b06b145dfb2cec

Fixes MS Office 2000/2003 installers and probably others. CORE-17693

dll/win32/msi/package.c

index 5aa3dd0..f65e2ee 100644 (file)
@@ -1498,6 +1498,8 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
         r = get_local_package( file, localfile );
         if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
         {
+            DWORD localfile_attr;
+
             r = msi_create_empty_local_file( localfile, dotmsi );
             if (r != ERROR_SUCCESS)
             {
@@ -1514,6 +1516,11 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
                 return r;
             }
             delete_on_close = TRUE;
+
+            /* Remove read-only bit, we are opening it with write access in MSI_OpenDatabaseW below. */
+            localfile_attr = GetFileAttributesW( localfile );
+            if (localfile_attr & FILE_ATTRIBUTE_READONLY)
+                SetFileAttributesW( localfile, localfile_attr & ~FILE_ATTRIBUTE_READONLY);
         }
         TRACE("opening package %s\n", debugstr_w( localfile ));
         r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );