diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-19 18:49:29 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-19 20:06:57 +0200 |
commit | 7a4772096d307bbfa7842ad7346d63d633ba6c23 (patch) | |
tree | 5a7a3e67c9fad844a10dc8362c7df7122f8ba200 /comphelper | |
parent | adb38e36e3944b47dbf278f882dd07cbabea5ced (diff) |
Fix moving temp file in tryDisableHWAcceleration on Windows
In my debug build, using safe mode dialog, Disable hardware acceleration
setting does not apply. In BackupFileHelper::tryDisableHWAcceleration,
osl::File::move fails with osl_File_E_ACCES, and internally GetLastError
after MoveFileExW reports ERROR_SHARING_VIOLATION.
The problem is that the tempfile is still in use by xTempFile. Closing
it, and making sure that the file doesn't get removed in the dtor, fixes
the problem.
In case something goes wrong, the tempfile would get removed in app
cleanup anyway, when session temp directory gets removed.
Change-Id: I4568f60b2b50a4038cba2e7a65033cb57e8b6edb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122274
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/backupfilehelper.cxx | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx index 807ca5878608..d03662381939 100644 --- a/comphelper/source/misc/backupfilehelper.cxx +++ b/comphelper/source/misc/backupfilehelper.cxx @@ -1910,26 +1910,31 @@ namespace comphelper xRootElement->appendChild(lcl_getConfigElement(xDocument, "/org.openoffice.Office.Common/VCL", "ForceSkiaRaster", "true")); - // write back - uno::Reference< xml::sax::XSAXSerializable > xSerializer(xDocument, uno::UNO_QUERY); + OUString aTempURL; + { + // use the scope to make sure that the temp file gets properly closed before move - if (!xSerializer.is()) - return; + // write back + uno::Reference< xml::sax::XSAXSerializable > xSerializer(xDocument, uno::UNO_QUERY); - // create a SAXWriter - uno::Reference< xml::sax::XWriter > const xSaxWriter = xml::sax::Writer::create(xContext); - uno::Reference< io::XStream > xTempFile = io::TempFile::create(xContext); - uno::Reference< io::XOutputStream > xOutStrm = xTempFile->getOutputStream(); + if (!xSerializer.is()) + return; - // set output stream and do the serialization - xSaxWriter->setOutputStream(xOutStrm); - xSerializer->serialize(xSaxWriter, uno::Sequence< beans::StringPair >()); + // create a SAXWriter + uno::Reference< xml::sax::XWriter > const xSaxWriter = xml::sax::Writer::create(xContext); + uno::Reference< io::XTempFile > xTempFile = io::TempFile::create(xContext); + xTempFile->setRemoveFile(false); // avoid removal of tempfile when leaving the scope + uno::Reference< io::XOutputStream > xOutStrm = xTempFile->getOutputStream(); - // get URL from temp file - uno::Reference < beans::XPropertySet > xTempFileProps(xTempFile, uno::UNO_QUERY); - uno::Any aUrl = xTempFileProps->getPropertyValue("Uri"); - OUString aTempURL; - aUrl >>= aTempURL; + // set output stream and do the serialization + xSaxWriter->setOutputStream(xOutStrm); + xSerializer->serialize(xSaxWriter, uno::Sequence< beans::StringPair >()); + + // get URL from temp file + uno::Reference < beans::XPropertySet > xTempFileProps(xTempFile, uno::UNO_QUERY); + uno::Any aUrl = xTempFileProps->getPropertyValue("Uri"); + aUrl >>= aTempURL; + } // copy back file if (aTempURL.isEmpty() || !DirectoryHelper::fileExists(aTempURL)) |