configmgr/source/writemodfile.cxx | 2 +- include/osl/file.hxx | 2 +- sal/osl/w32/file.cxx | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-)
New commits: commit a5167ae1d69dc6c9a88807113c9315860048f462 Author: Mike Kaganski <[email protected]> AuthorDate: Tue Dec 14 10:58:18 2021 +0300 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Dec 14 11:37:24 2021 +0100 tdf#81146: try to make saving registrymodifications.xcu more robust ... by use of osl::File::replace, which is "atomic" on Windows, instead of osl::File::move. Change-Id: Ia49212f0d1cc75292f72ce219aee513e2d250ec4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126801 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx index 359b5d7a9a06..09fe0949b0e9 100644 --- a/configmgr/source/writemodfile.cxx +++ b/configmgr/source/writemodfile.cxx @@ -114,7 +114,7 @@ void TempFile::closeAndRename(const OUString &_url) { throw css::uno::RuntimeException( "cannot close " + url); } - if (osl::File::move(url, _url) != osl::FileBase::E_None) { + if (osl::File::replace(url, _url) != osl::FileBase::E_None) { throw css::uno::RuntimeException( "cannot move " + url); } commit 40c1db47ee701da5a9d2c81ad3d13bb7c8179787 Author: Mike Kaganski <[email protected]> AuthorDate: Tue Dec 14 10:52:34 2021 +0300 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Dec 14 11:37:13 2021 +0100 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 <[email protected]> diff --git a/include/osl/file.hxx b/include/osl/file.hxx index 0608101ea4b5..fcbabe96d674 100644 --- a/include/osl/file.hxx +++ b/include/osl/file.hxx @@ -1307,7 +1307,7 @@ public: Moves or renames a file, replacing an existing file if exist. If the old file existed, moved file's metadata, e.g. creation time (on FSes which keep files' creation time) or ACLs, are set to old one's (to keep the old file's identity) - currently this is only - implemented fully on Windows; on other platforms, this is mostly equivalent to osl_moveFile. + implemented fully on Windows; on other platforms, this is mostly equivalent to move(). @param[in] ustrSourceFileURL Full qualified URL of the source file. 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);
