Skip to content

Commit 20970b4

Browse files
Remove stale binary previews from output ODF file
The ODF original file includes a binary graphic version of all of the graphs. These graphs are no longer valid once we've replaced the data in the sheet, so remove them from the file and manifest to ensure OpenOffice will rebuild the graph using our new data. Same for the thumbnail image.
1 parent acd3d53 commit 20970b4

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

ezfio.ps1

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,10 @@ function DefineTests {
546546
$threadslist = (1, 2, 4, 8, 16, 32, 64, 128, 256)
547547
$shorttime = 120 # Runtime of point tests
548548
$longtime = 1200 # Runtime of long-running tests
549-
549+
$threadslist=(1)
550+
$bslist=(4096)
551+
$shorttime=2
552+
$longtime=4
550553
function AddTest( $name, $seqrand, $writepct, $blocksize, $threads, $qdperthread, $desc, $cmdline ) {
551554
if ($threads -eq "") { $qd = '' } else { $qd = ([int]$threads) * ([int]$qdperthread) }
552555
if ($blocksize -ne "") { if ($blocksize -lt 1024) { $bsstr = "${blocksize}b" } else { $bsstr = "{0:N0}K" -f ([int]$blocksize/1024) } }
@@ -949,7 +952,10 @@ VNEBUEsFBgAAAAABAAEAWgAAAFQAAAAAAA==
949952
$zasrc = [System.IO.Compression.ZipFile]::Open( $odssrc, [System.IO.Compression.ZipArchiveMode]::Read )
950953
$zadst = [System.IO.Compression.ZipFile]::Open( $odsdest, [System.IO.Compression.ZipArchiveMode]::Update )
951954
foreach ($entry in $zasrc.Entries) {
952-
if ($entry.FullName -eq "mimetype") { continue }
955+
if (($entry.FullName -eq "mimetype") -or $entry.FullName.StartsWith("Thumbnails") -or $entry.FullName.StartsWith("ObjectReplacement")) {
956+
# Skip binary versions, and the copied-over mimetype
957+
continue
958+
}
953959
$newentry = $zadst.CreateEntry( $entry )
954960
if ($entry.FullName.EndsWith("/") -or $entry.FullName.EndsWith("\")) {
955961
# Directory, don't copy anything
@@ -958,6 +964,20 @@ VNEBUEsFBgAAAAABAAEAWgAAAFQAAAAAAA==
958964
$wr = New-Object System.IO.StreamWriter( $newentry.Open() )
959965
$wr.Write( $xmltext )
960966
$wr.Close()
967+
} elseif ($entry.FullName -eq "META-INF/manifest.xml") {
968+
# Remove ObjectReplacements from the list
969+
$rd = New-Object System.IO.StreamReader( $entry.Open() )
970+
$wr = New-Object System.IO.StreamWriter( $newentry.Open() )
971+
$rdbytes = $rd.ReadToEnd()
972+
$rd.close()
973+
$lines = $rdbytes.Split("`n")
974+
foreach ($line in $lines) {
975+
if ( -not ( ($line -contains "ObjectReplacement") -or ($line -contains "Thumbnails") ) ) {
976+
$wr.Write($line)
977+
$wr.Write("`n")
978+
}
979+
}
980+
$wr.Close();
961981
} else {
962982
# Copying data for from the source ZIP
963983
$wr = New-Object System.IO.StreamWriter( $newentry.Open() )

ezfio.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,11 @@ def UpdateContentXMLToODS_text( odssrc, odsdest, xmltext ):
776776
Replace content.xml in an ODS file with in-memory, modified copy and
777777
write new ODS. Can't just copy source.zip and replace one file, the
778778
output ZIP file is not correct in many cases (opens in Excel but fails
779-
ODF validation and LibreOffice fails to load under Windows)
779+
ODF validation and LibreOffice fails to load under Windows).
780+
781+
Also strips out any binary versions of objects and the thumbnail,
782+
since they are no longer valid once we've changed the data in the
783+
sheet.
780784
"""
781785
if os.path.exists(odsdest):
782786
os.unlink(odsdest)
@@ -802,6 +806,18 @@ def UpdateContentXMLToODS_text( odssrc, odsdest, xmltext ):
802806
continue
803807
elif entry == "content.xml":
804808
zadst.writestr( "content.xml", xmltext)
809+
elif entry == "META-INF/manifest.xml":
810+
# Remove ObjectReplacements from the list
811+
rdbytes = zasrc.read(entry)
812+
outbytes = ""
813+
lines = rdbytes.split("\n")
814+
for line in lines:
815+
if not ( ("ObjectReplacement" in line) or ("Thumbnails" in line) ):
816+
outbytes = outbytes + line + "\n"
817+
zadst.writestr(entry, outbytes)
818+
elif ("Thumbnails" in entry) or ("ObjectReplacement" in entry):
819+
# Skip binary versions
820+
continue
805821
else:
806822
rdbytes = zasrc.read(entry)
807823
zadst.writestr(entry, rdbytes)

0 commit comments

Comments
 (0)