From 570d7f9c9f5befdb84e213916036a2b9c7321259 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 8 Aug 2017 12:08:49 +0200 Subject: tdf#111481 package: seek to 0 before truncate() With this, the ZIP files created by the EPUB export don't trigger this warning on 'unzip -l': warning [test.epub]: 2546 extra bytes at beginning or within zipfile Change-Id: Ic9111d2c97b9337cf39a023def4afe4c64c4a3e5 Reviewed-on: https://gerrit.libreoffice.org/40873 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- package/source/zippackage/ZipPackage.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'package') diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 66e40cb9d410..33ed9c1bc023 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -1395,6 +1395,14 @@ void SAL_CALL ZipPackage::commitChanges() try { xOutputStream = m_xStream->getOutputStream(); + + // Make sure we avoid a situation where the current position is + // not zero, but the underlying file is truncated in the + // meantime. + uno::Reference xSeekable(xOutputStream, uno::UNO_QUERY); + if (xSeekable.is()) + xSeekable->seek(0); + uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY_THROW ); // after successful truncation the original file contents are already lost -- cgit