summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-09-29 16:49:06 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-09-29 17:22:16 +0100
commita8f32f34b68d9368db5371c0889e7b5955b5a10f (patch)
treea7fa50c5ccd2f8749ea85a2028b3dfafa126a218
parent1498c4f631e9c90b11dbdb18e8b094b90e143466 (diff)
Resolves: tdf#67555 writeFile honors ntfs symlinks as it turns out
and correctly truncates the file without replacing it by a delete + recreate. So we can drop the custom temp directory+move code of fdo#42122 - truncate files that shrink to avoid dictionary corruption This reverts commit 28300209604ee1bb8e5050322b29e95a07f679d8. and so don't need fdo#66420: fix user dictionaries on Windows This reverts commit d68de5195605bd9236851e0714dd9b03b0f5f3be. Change-Id: I7f2010f4113f78cd0667632253b56055d189cbff
-rw-r--r--linguistic/source/dicimp.cxx97
1 files changed, 30 insertions, 67 deletions
diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx
index eac56461579c..b588be1fb569 100644
--- a/linguistic/source/dicimp.cxx
+++ b/linguistic/source/dicimp.cxx
@@ -36,6 +36,7 @@
#include <com/sun/star/linguistic2/DictionaryType.hpp>
#include <com/sun/star/linguistic2/DictionaryEventFlags.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>
+#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
@@ -368,61 +369,6 @@ static OString formatForSave(const uno::Reference< XDictionaryEntry > &xEntry,
return aStr.makeStringAndClear();
}
-struct TmpDictionary
-{
- OUString maURL, maTmpURL;
- uno::Reference< ucb::XSimpleFileAccess3 > mxAccess;
-
- void cleanTmpFile()
- {
- try
- {
- if (mxAccess.is())
- {
- mxAccess->kill(maTmpURL);
- }
- }
- catch (const uno::Exception &) { }
- }
- explicit TmpDictionary(const OUString &rURL)
- : maURL( rURL )
- {
- maTmpURL = maURL + ".tmp";
- }
- ~TmpDictionary()
- {
- cleanTmpFile();
- }
-
- uno::Reference< io::XStream > openTmpFile()
- {
- uno::Reference< io::XStream > xStream;
-
- try
- {
- mxAccess = ucb::SimpleFileAccess::create(
- comphelper::getProcessComponentContext());
- xStream = mxAccess->openFileReadWrite(maTmpURL);
- } catch (const uno::Exception &) { }
-
- return xStream;
- }
-
- sal_uLong renameTmpToURL()
- {
- try
- {
- mxAccess->move(maTmpURL, maURL);
- }
- catch (const uno::Exception &)
- {
- SAL_WARN( "linguistic", "failed to overwrite dict" );
- return static_cast< sal_uLong >(-1);
- }
- return 0;
- }
-};
-
sal_uLong DictionaryNeo::saveEntries(const OUString &rURL)
{
MutexGuard aGuard( GetLinguMutex() );
@@ -431,16 +377,23 @@ sal_uLong DictionaryNeo::saveEntries(const OUString &rURL)
return 0;
DBG_ASSERT(!INetURLObject( rURL ).HasError(), "lng : invalid URL");
- // lifecycle manage the .tmp file
- TmpDictionary aTmpDictionary(rURL);
- uno::Reference< io::XStream > xStream = aTmpDictionary.openTmpFile();
+ uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
+ // get XOutputStream stream
+ uno::Reference<io::XStream> xStream;
+ try
+ {
+ xStream = io::TempFile::create(xContext);
+ }
+ catch (const uno::Exception &)
+ {
+ DBG_ASSERT( 0, "failed to get input stream" );
+ }
if (!xStream.is())
return static_cast< sal_uLong >(-1);
SvStreamPtr pStream = SvStreamPtr( utl::UcbStreamHelper::CreateStream( xStream ) );
-
// Always write as the latest version, i.e. DIC_VERSION_7
rtl_TextEncoding eEnc = RTL_TEXTENCODING_UTF8;
@@ -475,16 +428,26 @@ sal_uLong DictionaryNeo::saveEntries(const OUString &rURL)
OString aOutStr = formatForSave(aEntrie, eEnc);
pStream->WriteLine (aOutStr);
if (0 != (nErr = pStream->GetError()))
- break;
+ return nErr;
}
- pStream.reset(); // fdo#66420 close streams so Win32 can move the file
- xStream.clear();
- nErr = aTmpDictionary.renameTmpToURL();
-
- //If we are migrating from an older version, then on first successful
- //write, we're now converted to the latest version, i.e. DIC_VERSION_7
- nDicVersion = DIC_VERSION_7;
+ try
+ {
+ pStream.reset();
+ uno::Reference< ucb::XSimpleFileAccess3 > xAccess(ucb::SimpleFileAccess::create(xContext));
+ Reference<io::XInputStream> xInputStream(xStream, UNO_QUERY_THROW);
+ uno::Reference<io::XSeekable> xSeek(xInputStream, UNO_QUERY_THROW);
+ xSeek->seek(0);
+ xAccess->writeFile(rURL, xInputStream);
+ //If we are migrating from an older version, then on first successful
+ //write, we're now converted to the latest version, i.e. DIC_VERSION_7
+ nDicVersion = DIC_VERSION_7;
+ }
+ catch (const uno::Exception &)
+ {
+ DBG_ASSERT( 0, "failed to write stream" );
+ return static_cast< sal_uLong >(-1);
+ }
return nErr;
}