diff options
Diffstat (limited to 'src')
4 files changed, 100 insertions, 0 deletions
diff --git a/src/ext/Util/ca/TouchFile.cpp b/src/ext/Util/ca/TouchFile.cpp index 2c3918af..4a3b57b4 100644 --- a/src/ext/Util/ca/TouchFile.cpp +++ b/src/ext/Util/ca/TouchFile.cpp | |||
| @@ -23,6 +23,7 @@ static HRESULT SetExistingFileModifiedTime( | |||
| 23 | ) | 23 | ) |
| 24 | { | 24 | { |
| 25 | HRESULT hr = S_OK; | 25 | HRESULT hr = S_OK; |
| 26 | #ifndef _WIN64 | ||
| 26 | BOOL fReenableFileSystemRedirection = FALSE; | 27 | BOOL fReenableFileSystemRedirection = FALSE; |
| 27 | 28 | ||
| 28 | if (f64Bit) | 29 | if (f64Bit) |
| @@ -32,14 +33,20 @@ static HRESULT SetExistingFileModifiedTime( | |||
| 32 | 33 | ||
| 33 | fReenableFileSystemRedirection = TRUE; | 34 | fReenableFileSystemRedirection = TRUE; |
| 34 | } | 35 | } |
| 36 | #else | ||
| 37 | UNREFERENCED_PARAMETER(wzId); | ||
| 38 | UNREFERENCED_PARAMETER(f64Bit); | ||
| 39 | #endif | ||
| 35 | 40 | ||
| 36 | hr = FileSetTime(wzPath, NULL, NULL, pftModified); | 41 | hr = FileSetTime(wzPath, NULL, NULL, pftModified); |
| 37 | 42 | ||
| 43 | #ifndef _WIN64 | ||
| 38 | LExit: | 44 | LExit: |
| 39 | if (fReenableFileSystemRedirection) | 45 | if (fReenableFileSystemRedirection) |
| 40 | { | 46 | { |
| 41 | WcaRevertWow64FSRedirection(); | 47 | WcaRevertWow64FSRedirection(); |
| 42 | } | 48 | } |
| 49 | #endif | ||
| 43 | 50 | ||
| 44 | return hr; | 51 | return hr; |
| 45 | } | 52 | } |
| @@ -83,6 +90,7 @@ static BOOL TryGetExistingFileModifiedTime( | |||
| 83 | ) | 90 | ) |
| 84 | { | 91 | { |
| 85 | HRESULT hr = S_OK; | 92 | HRESULT hr = S_OK; |
| 93 | #ifndef _WIN64 | ||
| 86 | BOOL fReenableFileSystemRedirection = FALSE; | 94 | BOOL fReenableFileSystemRedirection = FALSE; |
| 87 | 95 | ||
| 88 | if (f64Bit) | 96 | if (f64Bit) |
| @@ -92,6 +100,10 @@ static BOOL TryGetExistingFileModifiedTime( | |||
| 92 | 100 | ||
| 93 | fReenableFileSystemRedirection = TRUE; | 101 | fReenableFileSystemRedirection = TRUE; |
| 94 | } | 102 | } |
| 103 | #else | ||
| 104 | UNREFERENCED_PARAMETER(wzId); | ||
| 105 | UNREFERENCED_PARAMETER(f64Bit); | ||
| 106 | #endif | ||
| 95 | 107 | ||
| 96 | hr = FileGetTime(wzPath, NULL, NULL, pftModified); | 108 | hr = FileGetTime(wzPath, NULL, NULL, pftModified); |
| 97 | if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) | 109 | if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) |
| @@ -104,11 +116,13 @@ static BOOL TryGetExistingFileModifiedTime( | |||
| 104 | WcaLog(LOGMSG_STANDARD, "Cannot access modified timestamp for file: '%ls' due to error: 0x%x. Continuing with out rollback for: %ls", wzPath, hr, wzId); | 116 | WcaLog(LOGMSG_STANDARD, "Cannot access modified timestamp for file: '%ls' due to error: 0x%x. Continuing with out rollback for: %ls", wzPath, hr, wzId); |
| 105 | } | 117 | } |
| 106 | 118 | ||
| 119 | #ifndef _WIN64 | ||
| 107 | LExit: | 120 | LExit: |
| 108 | if (fReenableFileSystemRedirection) | 121 | if (fReenableFileSystemRedirection) |
| 109 | { | 122 | { |
| 110 | WcaRevertWow64FSRedirection(); | 123 | WcaRevertWow64FSRedirection(); |
| 111 | } | 124 | } |
| 125 | #endif | ||
| 112 | 126 | ||
| 113 | return SUCCEEDED(hr); | 127 | return SUCCEEDED(hr); |
| 114 | } | 128 | } |
| @@ -217,9 +231,17 @@ extern "C" UINT WINAPI WixTouchFileDuringInstall( | |||
| 217 | hr = WcaInitialize(hInstall, "WixTouchFileDuringInstall"); | 231 | hr = WcaInitialize(hInstall, "WixTouchFileDuringInstall"); |
| 218 | ExitOnFailure(hr, "Failed to initialize WixTouchFileDuringInstall."); | 232 | ExitOnFailure(hr, "Failed to initialize WixTouchFileDuringInstall."); |
| 219 | 233 | ||
| 234 | #ifndef _WIN64 | ||
| 235 | WcaInitializeWow64(); | ||
| 236 | #endif | ||
| 237 | |||
| 220 | hr = ProcessTouchFileTable(TRUE); | 238 | hr = ProcessTouchFileTable(TRUE); |
| 221 | 239 | ||
| 222 | LExit: | 240 | LExit: |
| 241 | #ifndef _WIN64 | ||
| 242 | WcaFinalizeWow64(); | ||
| 243 | #endif | ||
| 244 | |||
| 223 | DWORD er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | 245 | DWORD er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; |
| 224 | return WcaFinalize(er); | 246 | return WcaFinalize(er); |
| 225 | } | 247 | } |
| @@ -236,9 +258,17 @@ extern "C" UINT WINAPI WixTouchFileDuringUninstall( | |||
| 236 | hr = WcaInitialize(hInstall, "WixTouchFileDuringUninstall"); | 258 | hr = WcaInitialize(hInstall, "WixTouchFileDuringUninstall"); |
| 237 | ExitOnFailure(hr, "Failed to initialize WixTouchFileDuringUninstall."); | 259 | ExitOnFailure(hr, "Failed to initialize WixTouchFileDuringUninstall."); |
| 238 | 260 | ||
| 261 | #ifndef _WIN64 | ||
| 262 | WcaInitializeWow64(); | ||
| 263 | #endif | ||
| 264 | |||
| 239 | hr = ProcessTouchFileTable(FALSE); | 265 | hr = ProcessTouchFileTable(FALSE); |
| 240 | 266 | ||
| 241 | LExit: | 267 | LExit: |
| 268 | #ifndef _WIN64 | ||
| 269 | WcaFinalizeWow64(); | ||
| 270 | #endif | ||
| 271 | |||
| 242 | DWORD er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | 272 | DWORD er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; |
| 243 | return WcaFinalize(er); | 273 | return WcaFinalize(er); |
| 244 | } | 274 | } |
| @@ -261,6 +291,10 @@ extern "C" UINT WINAPI WixExecuteTouchFile( | |||
| 261 | hr = WcaInitialize(hInstall, "WixExecuteTouchFile"); | 291 | hr = WcaInitialize(hInstall, "WixExecuteTouchFile"); |
| 262 | ExitOnFailure(hr, "Failed to initialize WixExecuteTouchFile."); | 292 | ExitOnFailure(hr, "Failed to initialize WixExecuteTouchFile."); |
| 263 | 293 | ||
| 294 | #ifndef _WIN64 | ||
| 295 | WcaInitializeWow64(); | ||
| 296 | #endif | ||
| 297 | |||
| 264 | hr = WcaGetProperty(L"CustomActionData", &sczData); | 298 | hr = WcaGetProperty(L"CustomActionData", &sczData); |
| 265 | ExitOnFailure(hr, "Failed to get custom action data for WixExecuteTouchFile."); | 299 | ExitOnFailure(hr, "Failed to get custom action data for WixExecuteTouchFile."); |
| 266 | 300 | ||
| @@ -299,6 +333,10 @@ extern "C" UINT WINAPI WixExecuteTouchFile( | |||
| 299 | } | 333 | } |
| 300 | 334 | ||
| 301 | LExit: | 335 | LExit: |
| 336 | #ifndef _WIN64 | ||
| 337 | WcaFinalizeWow64(); | ||
| 338 | #endif | ||
| 339 | |||
| 302 | ReleaseStr(sczPath); | 340 | ReleaseStr(sczPath); |
| 303 | ReleaseStr(sczId); | 341 | ReleaseStr(sczId); |
| 304 | ReleaseStr(sczData); | 342 | ReleaseStr(sczData); |
diff --git a/src/test/msi/TestData/TouchFileTests/TouchFile/Package.wxs b/src/test/msi/TestData/TouchFileTests/TouchFile/Package.wxs new file mode 100644 index 00000000..23bd195b --- /dev/null +++ b/src/test/msi/TestData/TouchFileTests/TouchFile/Package.wxs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> | ||
| 2 | <Package Name="~TouchFile" Version="1.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"> | ||
| 3 | <Component> | ||
| 4 | <File Source="$(sys.SOURCEFILEPATH)" /> | ||
| 5 | <util:TouchFile Path="[LocalAppDataFolder]touch-file-test.txt" /> | ||
| 6 | </Component> | ||
| 7 | </Package> | ||
| 8 | </Wix> | ||
diff --git a/src/test/msi/TestData/TouchFileTests/TouchFile/TouchFile.wixproj b/src/test/msi/TestData/TouchFileTests/TouchFile/TouchFile.wixproj new file mode 100644 index 00000000..58321e7e --- /dev/null +++ b/src/test/msi/TestData/TouchFileTests/TouchFile/TouchFile.wixproj | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> | ||
| 2 | <Project Sdk="WixToolset.Sdk"> | ||
| 3 | <ItemGroup> | ||
| 4 | <PackageReference Include="WixToolset.Util.wixext" /> | ||
| 5 | </ItemGroup> | ||
| 6 | </Project> \ No newline at end of file | ||
diff --git a/src/test/msi/WixToolsetTest.MsiE2E/TouchFileTests.cs b/src/test/msi/WixToolsetTest.MsiE2E/TouchFileTests.cs new file mode 100644 index 00000000..f7666825 --- /dev/null +++ b/src/test/msi/WixToolsetTest.MsiE2E/TouchFileTests.cs | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolsetTest.MsiE2E; | ||
| 4 | |||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | using WixTestTools; | ||
| 8 | using Xunit; | ||
| 9 | using Xunit.Abstractions; | ||
| 10 | |||
| 11 | public class TouchFileTests : MsiE2ETests | ||
| 12 | { | ||
| 13 | public TouchFileTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | [RuntimeFact] | ||
| 18 | public void CanValidateTouchFile() | ||
| 19 | { | ||
| 20 | var touchFileTestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "touch-file-test.txt"); | ||
| 21 | |||
| 22 | try | ||
| 23 | { | ||
| 24 | var touchFileTime = new DateTime(2004, 4, 5, 0, 0, 0, DateTimeKind.Utc); | ||
| 25 | |||
| 26 | File.WriteAllText(touchFileTestPath, "This file exists to test CanValidateTouchFile()"); | ||
| 27 | File.SetCreationTimeUtc(touchFileTestPath, touchFileTime); | ||
| 28 | File.SetLastAccessTimeUtc(touchFileTestPath, touchFileTime); | ||
| 29 | File.SetLastWriteTimeUtc(touchFileTestPath, touchFileTime); | ||
| 30 | |||
| 31 | var product = this.CreatePackageInstaller("TouchFile"); | ||
| 32 | |||
| 33 | var justBeforeInstall = DateTime.UtcNow; | ||
| 34 | product.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); | ||
| 35 | |||
| 36 | var touchFile = new FileInfo(touchFileTestPath); | ||
| 37 | Assert.Equal(touchFileTime, touchFile.CreationTimeUtc); | ||
| 38 | Assert.Equal(touchFileTime, touchFile.LastAccessTimeUtc); | ||
| 39 | Assert.True(touchFile.LastWriteTimeUtc >= justBeforeInstall, $"Touch file {touchFileTestPath} last write time: {touchFile.LastWriteTimeUtc} of file should have been updated to at least: {justBeforeInstall}"); | ||
| 40 | |||
| 41 | product.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); | ||
| 42 | } | ||
| 43 | finally | ||
| 44 | { | ||
| 45 | File.Delete(touchFileTestPath); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
