diff options
Diffstat (limited to '')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/fileutil.cpp | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp index 31802d29..abe1f6ad 100644 --- a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp | |||
| @@ -32,7 +32,7 @@ __out LPWSTR *ppwzFileNameNoExtension | |||
| 32 | ) | 32 | ) |
| 33 | { | 33 | { |
| 34 | Assert(wzFileName && *wzFileName); | 34 | Assert(wzFileName && *wzFileName); |
| 35 | 35 | ||
| 36 | HRESULT hr = S_OK; | 36 | HRESULT hr = S_OK; |
| 37 | size_t cchFileName = 0; | 37 | size_t cchFileName = 0; |
| 38 | LPWSTR pwzFileNameNoExtension = NULL; | 38 | LPWSTR pwzFileNameNoExtension = NULL; |
| @@ -90,7 +90,7 @@ extern "C" HRESULT DAPI FileChangeExtension( | |||
| 90 | 90 | ||
| 91 | LExit: | 91 | LExit: |
| 92 | ReleaseStr(sczFileName); | 92 | ReleaseStr(sczFileName); |
| 93 | 93 | ||
| 94 | return hr; | 94 | return hr; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| @@ -140,7 +140,7 @@ extern "C" HRESULT DAPI FileAddSuffixToBaseName( | |||
| 140 | 140 | ||
| 141 | LExit: | 141 | LExit: |
| 142 | ReleaseStr(sczNewFileName); | 142 | ReleaseStr(sczNewFileName); |
| 143 | 143 | ||
| 144 | return hr; | 144 | return hr; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| @@ -1340,6 +1340,51 @@ LExit: | |||
| 1340 | 1340 | ||
| 1341 | 1341 | ||
| 1342 | /******************************************************************* | 1342 | /******************************************************************* |
| 1343 | FileCreateWithRetry - create a file with multiple attempts if necessary | ||
| 1344 | |||
| 1345 | ********************************************************************/ | ||
| 1346 | extern "C" HRESULT DAPI FileCreateWithRetry( | ||
| 1347 | __in LPCWSTR wzFile, | ||
| 1348 | __in DWORD dwDesiredAccess, | ||
| 1349 | __in DWORD dwShareMode, | ||
| 1350 | __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, | ||
| 1351 | __in DWORD dwCreationDisposition, | ||
| 1352 | __in DWORD dwFlagsAndAttributes, | ||
| 1353 | __in DWORD cRetry, | ||
| 1354 | __in DWORD dwWaitMilliseconds, | ||
| 1355 | __out HANDLE* phFile | ||
| 1356 | ) | ||
| 1357 | { | ||
| 1358 | HRESULT hr = HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE); | ||
| 1359 | |||
| 1360 | *phFile = INVALID_HANDLE_VALUE; | ||
| 1361 | |||
| 1362 | for (DWORD i = 0; i <= cRetry; ++i) | ||
| 1363 | { | ||
| 1364 | if (0 < i) | ||
| 1365 | { | ||
| 1366 | ::Sleep(dwWaitMilliseconds); | ||
| 1367 | } | ||
| 1368 | |||
| 1369 | *phFile = ::CreateFileW(wzFile, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, NULL); | ||
| 1370 | if (INVALID_HANDLE_VALUE == *phFile) | ||
| 1371 | { | ||
| 1372 | DWORD er = ::GetLastError(); | ||
| 1373 | hr = HRESULT_FROM_WIN32(er ? er : ERROR_INVALID_HANDLE); | ||
| 1374 | } | ||
| 1375 | else | ||
| 1376 | { | ||
| 1377 | hr = S_OK; | ||
| 1378 | break; | ||
| 1379 | } | ||
| 1380 | } | ||
| 1381 | FileExitOnRootFailure(hr, "Failed to create file: %ls after %u retries.", wzFile, cRetry); | ||
| 1382 | |||
| 1383 | LExit: | ||
| 1384 | return hr; | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | /******************************************************************* | ||
| 1343 | FileIsSame | 1388 | FileIsSame |
| 1344 | 1389 | ||
| 1345 | ********************************************************************/ | 1390 | ********************************************************************/ |
| @@ -1479,7 +1524,7 @@ extern "C" HRESULT DAPI FileResetTime( | |||
| 1479 | 1524 | ||
| 1480 | hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); | 1525 | hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
| 1481 | FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); | 1526 | FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); |
| 1482 | 1527 | ||
| 1483 | if (!::GetFileTime(hFile, &ftCreateTime, NULL, NULL)) | 1528 | if (!::GetFileTime(hFile, &ftCreateTime, NULL, NULL)) |
| 1484 | { | 1529 | { |
| 1485 | FileExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile); | 1530 | FileExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile); |
