diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-12-14 10:52:34 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-12-14 11:37:13 +0100 |
commit | 40c1db47ee701da5a9d2c81ad3d13bb7c8179787 (patch) | |
tree | 1b2a437996872543db502eee9cf75ae20aaf6a1e /sal | |
parent | 64fcf278830a33114f0fa5884767f24edf32cb12 (diff) |
osl_replaceFile: fallback to osl_moveFile in more cases on Windows
E.g., calling it with files residing on different volumes, ReplaceFileW
will fail with ERROR_UNABLE_TO_MOVE_REPLACEMENT. Handle that error, and
also the two other error codes specifically described at [1], to allow
more universal use of osl_replaceFile / osl::File::replace, which is
"atomic" on Windows, since it uses ReplaceFileW that is suggested as a
replacement for Transactional NTFS [2].
[1] https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-replacefilew
[2] https://docs.microsoft.com/en-us/windows/win32/fileio/deprecation-of-txf
Change-Id: I501c267e5bdd88a33560d2bb916db1a0b6e01831
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126800
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/w32/file.cxx | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sal/osl/w32/file.cxx b/sal/osl/w32/file.cxx index 1c13b6211779..96b2bba4b486 100644 --- a/sal/osl/w32/file.cxx +++ b/sal/osl/w32/file.cxx @@ -1130,7 +1130,10 @@ oslFileError SAL_CALL osl_replaceFile(rtl_uString* strPath, rtl_uString* strDest nullptr, nullptr)) { DWORD dwError = GetLastError(); - if (dwError == ERROR_FILE_NOT_FOUND) // no strDestPath file? + if (dwError == ERROR_FILE_NOT_FOUND // no strDestPath file? + || dwError == ERROR_UNABLE_TO_MOVE_REPLACEMENT // e.g., files on different volumes + || dwError == ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 + || dwError == ERROR_UNABLE_TO_REMOVE_REPLACED) error = osl_moveFile(strPath, strDestPath); else error = oslTranslateFileError(dwError); |