Kaydet (Commit) 00eb8905 authored tarafından Caolán McNamara's avatar Caolán McNamara Kaydeden (comit) Andras Timar

Resolves: tdf#88314 close temp file after each thread completed

Change-Id: Ic2eec30cfb5f61c53777eefeeb8bad6f552da2fc
Reviewed-on: https://gerrit.libreoffice.org/17355Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
(cherry picked from commit 458bf081)

Related: tdf#88314 delete temp files

clear to close the inputstream before attempting to delete the temp file, which
is plausible as the windows-specific failure in earlier attempts at this

Change-Id: I751aa3a098dd960f56b77a5f5fc93783c1060556
Reviewed-on: https://gerrit.libreoffice.org/17531Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
(cherry picked from commit ef698035)
Signed-off-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst ba1cd694
...@@ -37,7 +37,8 @@ class ZipOutputEntry ...@@ -37,7 +37,8 @@ class ZipOutputEntry
{ {
::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
ZipUtils::Deflater m_aDeflater; ZipUtils::Deflater m_aDeflater;
css::uno::Reference< css::io::XTempFile > m_xTempFile; css::uno::Reference< css::uno::XComponentContext > m_xContext;
OUString m_aTempURL;
css::uno::Reference< css::io::XOutputStream > m_xOutStream; css::uno::Reference< css::io::XOutputStream > m_xOutStream;
::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
...@@ -58,14 +59,22 @@ public: ...@@ -58,14 +59,22 @@ public:
~ZipOutputEntry(); ~ZipOutputEntry();
css::uno::Reference< css::io::XInputStream > getData(); /* This block of methods is for threaded zipping, where we compress to a temp stream, whose
data is retrieved via getData */
ZipOutputEntry(
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false);
void createBufferFile();
void setParallelDeflateException(const ::css::uno::Any &rAny) { m_aParallelDeflateException = rAny; }
css::uno::Reference< css::io::XInputStream > getData() const;
::css::uno::Any getParallelDeflateException() const { return m_aParallelDeflateException; }
void closeBufferFile();
void deleteBufferFile();
ZipEntry* getZipEntry() { return m_pCurrentEntry; } ZipEntry* getZipEntry() { return m_pCurrentEntry; }
ZipPackageStream* getZipPackageStream() { return m_pCurrentStream; } ZipPackageStream* getZipPackageStream() { return m_pCurrentStream; }
bool isEncrypt() { return m_bEncryptCurrentEntry; } bool isEncrypt() { return m_bEncryptCurrentEntry; }
void setParallelDeflateException(const ::css::uno::Any &rAny) { m_aParallelDeflateException = rAny; }
::css::uno::Any getParallelDeflateException() const { return m_aParallelDeflateException; }
void closeEntry(); void closeEntry();
void write(const css::uno::Sequence< sal_Int8 >& rBuffer); void write(const css::uno::Sequence< sal_Int8 >& rBuffer);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <com/sun/star/io/TempFile.hpp> #include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/packages/zip/ZipConstants.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
#include <comphelper/storagehelper.hxx> #include <comphelper/storagehelper.hxx>
#include <osl/time.h> #include <osl/time.h>
...@@ -49,25 +51,40 @@ ZipOutputEntry::ZipOutputEntry( ...@@ -49,25 +51,40 @@ ZipOutputEntry::ZipOutputEntry(
bool bEncrypt) bool bEncrypt)
: m_aDeflateBuffer(n_ConstBufferSize) : m_aDeflateBuffer(n_ConstBufferSize)
, m_aDeflater(DEFAULT_COMPRESSION, true) , m_aDeflater(DEFAULT_COMPRESSION, true)
, m_xContext(rxContext)
, m_xOutStream(rxOutput)
, m_pCurrentEntry(&rEntry) , m_pCurrentEntry(&rEntry)
, m_nDigested(0) , m_nDigested(0)
, m_bEncryptCurrentEntry(bEncrypt) , m_bEncryptCurrentEntry(bEncrypt)
, m_pCurrentStream(pStream) , m_pCurrentStream(pStream)
{ {
if (rxOutput.is()) assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries");
{ assert(m_xOutStream.is());
m_xOutStream = rxOutput; if (m_bEncryptCurrentEntry)
}
else
{ {
m_xTempFile = io::TempFile::create(rxContext); m_xCipherContext = ZipFile::StaticGetCipher( m_xContext, pStream->GetEncryptionData(), true );
m_xOutStream = m_xTempFile->getOutputStream(); m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xContext, pStream->GetEncryptionData() );
} }
}
ZipOutputEntry::ZipOutputEntry(
const uno::Reference< uno::XComponentContext >& rxContext,
ZipEntry& rEntry,
ZipPackageStream* pStream,
bool bEncrypt)
: m_aDeflateBuffer(n_ConstBufferSize)
, m_aDeflater(DEFAULT_COMPRESSION, true)
, m_xContext(rxContext)
, m_pCurrentEntry(&rEntry)
, m_nDigested(0)
, m_bEncryptCurrentEntry(bEncrypt)
, m_pCurrentStream(pStream)
{
assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries"); assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries");
if (m_bEncryptCurrentEntry) if (m_bEncryptCurrentEntry)
{ {
m_xCipherContext = ZipFile::StaticGetCipher( rxContext, pStream->GetEncryptionData(), true ); m_xCipherContext = ZipFile::StaticGetCipher( m_xContext, pStream->GetEncryptionData(), true );
m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( rxContext, pStream->GetEncryptionData() ); m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xContext, pStream->GetEncryptionData() );
} }
} }
...@@ -75,12 +92,39 @@ ZipOutputEntry::~ZipOutputEntry() ...@@ -75,12 +92,39 @@ ZipOutputEntry::~ZipOutputEntry()
{ {
} }
uno::Reference< io::XInputStream > ZipOutputEntry::getData() void ZipOutputEntry::createBufferFile()
{
assert(!m_xOutStream.is() && m_aTempURL.isEmpty() &&
"should only be called in the threaded mode where there is no existing stream yet");
uno::Reference < beans::XPropertySet > xTempFileProps(
io::TempFile::create(m_xContext),
uno::UNO_QUERY_THROW );
xTempFileProps->setPropertyValue("RemoveFile", uno::makeAny(sal_False));
uno::Any aUrl = xTempFileProps->getPropertyValue( "Uri" );
aUrl >>= m_aTempURL;
assert(!m_aTempURL.isEmpty());
uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess(ucb::SimpleFileAccess::create(m_xContext));
m_xOutStream = xTempAccess->openFileWrite(m_aTempURL);
}
void ZipOutputEntry::closeBufferFile()
{ {
m_xOutStream->closeOutput(); m_xOutStream->closeOutput();
uno::Reference< io::XSeekable > xTempSeek(m_xOutStream, UNO_QUERY_THROW); m_xOutStream.clear();
xTempSeek->seek(0); }
return m_xTempFile->getInputStream();
void ZipOutputEntry::deleteBufferFile()
{
assert(!m_xOutStream.is() && !m_aTempURL.isEmpty());
uno::Reference < ucb::XSimpleFileAccess3 > xAccess(ucb::SimpleFileAccess::create(m_xContext));
xAccess->kill(m_aTempURL);
}
uno::Reference< io::XInputStream > ZipOutputEntry::getData() const
{
uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess(ucb::SimpleFileAccess::create(m_xContext));
return xTempAccess->openFileRead(m_aTempURL);
} }
void ZipOutputEntry::closeEntry() void ZipOutputEntry::closeEntry()
......
...@@ -121,10 +121,12 @@ void ZipOutputStream::finish() ...@@ -121,10 +121,12 @@ void ZipOutputStream::finish()
rawWrite(aSequence); rawWrite(aSequence);
} }
while (nRead == n_ConstBufferSize); while (nRead == n_ConstBufferSize);
xInput.clear();
rawCloseEntry(m_aEntries[i]->isEncrypt()); rawCloseEntry(m_aEntries[i]->isEncrypt());
m_aEntries[i]->getZipPackageStream()->successfullyWritten(m_aEntries[i]->getZipEntry()); m_aEntries[i]->getZipPackageStream()->successfullyWritten(m_aEntries[i]->getZipEntry());
m_aEntries[i]->deleteBufferFile();
delete m_aEntries[i]; delete m_aEntries[i];
} }
......
...@@ -474,8 +474,10 @@ private: ...@@ -474,8 +474,10 @@ private:
{ {
try try
{ {
mpEntry->createBufferFile();
deflateZipEntry(mpEntry, mxInStream); deflateZipEntry(mpEntry, mxInStream);
mxInStream.clear(); mxInStream.clear();
mpEntry->closeBufferFile();
} }
catch (const uno::Exception&) catch (const uno::Exception&)
{ {
...@@ -823,7 +825,6 @@ bool ZipPackageStream::saveChild( ...@@ -823,7 +825,6 @@ bool ZipPackageStream::saveChild(
{ {
// Start a new thread deflating this zip entry // Start a new thread deflating this zip entry
ZipOutputEntry *pZipEntry = new ZipOutputEntry( ZipOutputEntry *pZipEntry = new ZipOutputEntry(
css::uno::Reference<css::io::XOutputStream>(),
m_xContext, *pTempEntry, this, bToBeEncrypted); m_xContext, *pTempEntry, this, bToBeEncrypted);
rZipOut.addDeflatingThread( pZipEntry, new DeflateThread(pZipEntry, xStream) ); rZipOut.addDeflatingThread( pZipEntry, new DeflateThread(pZipEntry, xStream) );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment