Skip to content

Commit 053a557

Browse files
committed
patch sheets
1 parent 26a2911 commit 053a557

26 files changed

Lines changed: 40 additions & 27 deletions

File tree

src/DeterministicIoPackaging/DeterministicPackage.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ static void DuplicateEntry(Entry sourceEntry, Archive targetArchive)
4949
return;
5050
}
5151

52+
if (sourceEntry.IsWorksheetXml())
53+
{
54+
var xml = Sheet.Patch(sourceStream);
55+
SaveXml(xml, targetStream);
56+
return;
57+
}
58+
5259
sourceStream.CopyTo(targetStream);
5360
}
5461

@@ -83,6 +90,13 @@ static async Task DuplicateEntryAsync(Entry sourceEntry, Archive targetArchive,
8390
return;
8491
}
8592

93+
if (sourceEntry.IsWorksheetXml())
94+
{
95+
var xml = await Sheet.Patch(sourceStream, cancel);
96+
await SaveXml(xml, targetStream, cancel);
97+
return;
98+
}
99+
86100
await sourceStream.CopyToAsync(targetStream, cancel);
87101
}
88102

src/DeterministicIoPackaging/Patching/Relationships.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ public static XDocument Patch(Stream stream)
1313
public static async Task<XDocument> Patch(Stream stream, Cancel cancel)
1414
{
1515
var xml = await XDocument.LoadAsync(stream, LoadOptions.None, cancel);
16-
1716
Patch(xml);
18-
1917
return xml;
2018
}
19+
2120
static void Patch(XDocument xml)
2221
{
2322
var root = xml.Root!;

src/DeterministicIoPackaging/Patching/Sheet.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ internal static XDocument Patch(Stream stream)
77
return xml;
88
}
99

10+
public static async Task<XDocument> Patch(Stream stream, Cancel cancel)
11+
{
12+
var xml = await XDocument.LoadAsync(stream, LoadOptions.None, cancel);
13+
Patch(xml);
14+
return xml;
15+
}
16+
1017
static XNamespace xr = "http://schemas.microsoft.com/office/spreadsheetml/2014/revision";
1118
static XName xName = xr + "uid";
1219

src/DeterministicIoPackaging/Patching/Workbook.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
static class Workbook
22
{
33
static XNamespace mc = "http://schemas.openxmlformats.org/markup-compatibility/2006";
4+
static XName alternateContent = mc + "AlternateContent";
45
static XNamespace x15ac = "http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac";
6+
static XName abspath = x15ac + "absPath";
57

68
public static XDocument Patch(Stream stream)
79
{
810
var xml = XDocument.Load(stream);
9-
1011
Patch(xml);
11-
1212
return xml;
1313
}
1414

1515
public static async Task<XDocument> Patch(Stream stream, Cancel cancel)
1616
{
1717
var xml = await XDocument.LoadAsync(stream, LoadOptions.None, cancel);
18-
1918
Patch(xml);
20-
2119
return xml;
2220
}
2321

2422
static void Patch(XDocument xml)
2523
{
2624
var absPath = xml
27-
.Descendants(mc + "AlternateContent")
28-
.FirstOrDefault(_ => _.Descendants(x15ac + "absPath").Any());
25+
.Descendants(alternateContent)
26+
.FirstOrDefault(_ => _.Descendants(abspath).Any());
2927

3028
absPath?.Remove();
3129
}

src/DeterministicIoPackaging/Patching/WorkbookRelationships.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ public static XDocument Patch(Stream sourceStream)
1313
public static async Task<XDocument> Patch(Stream stream, Cancel cancel)
1414
{
1515
var xml = await XDocument.LoadAsync(stream, LoadOptions.None, cancel);
16-
1716
Patch(xml);
18-
1917
return xml;
2018
}
19+
2120
static void Patch(XDocument xml)
2221
{
2322
var root = xml.Root!;

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;CA1416;NU1608;NU1109</NoWarn>
5-
<Version>0.3.0</Version>
5+
<Version>0.4.0</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<Description>Modify System.IO.Packaging (https://learn.microsoft.com/en-us/dotnet/api/system.io.packaging) files to ensure they are deterministic. Helpful for testing, build reproducibility, security verification, and ensuring package integrity across different build environments.</Description>
-55 Bytes
Binary file not shown.
-49 Bytes
Binary file not shown.

src/Tests/Tests.AbsPathZip.DotNet/xl/worksheets/sheet1.verified.xml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac xr xr2 xr3" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3" xr:uid="{8CEE6BCD-0185-4B0D-A16D-65794877B9A9}"><dimension ref="A5" /><sheetViews><sheetView tabSelected="1" workbookViewId="0" topLeftCell="A1" /></sheetViews><sheetFormatPr defaultRowHeight="12.75" /><sheetData><row r="5" spans="1:1" ht="23.25" customHeight="1"><c r="A5" s="3" t="s"><v>30</v></c></row></sheetData><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5" /></worksheet>
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac xr xr2 xr3" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3"><dimension ref="A5" /><sheetViews><sheetView tabSelected="1" workbookViewId="0" topLeftCell="A1" /></sheetViews><sheetFormatPr defaultRowHeight="12.75" /><sheetData><row r="5" spans="1:1" ht="23.25" customHeight="1"><c r="A5" s="3" t="s"><v>30</v></c></row></sheetData><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5" /></worksheet>

0 commit comments

Comments
 (0)