Skip to content

Commit c9484e1

Browse files
committed
.
1 parent 70a637e commit c9484e1

22 files changed

Lines changed: 82 additions & 15 deletions

src/DeterministicIoPackaging/DeterministicPackage.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ public static partial class DeterministicPackage
55
public static DateTime StableDate { get; } = new(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
66
public static DateTimeOffset StableDateOffset { get; } = new(StableDate);
77

8-
private static IReadOnlyList<IPatcher> patchers = [
8+
static IReadOnlyList<IPatcher> patchers =
9+
[
910
new RelationshipPatcher(),
1011
new SheetPatcher(),
1112
new WorkbookPatcher(),
12-
new WorkbookRelationshipPatcher() ];
13+
new WorkbookRelationshipPatcher(),
14+
new CorePatcher()
15+
];
16+
1317
static Archive CreateArchive(Stream target) => new(target, ZipArchiveMode.Create, leaveOpen: true);
1418

1519
static Archive ReadArchive(Stream source)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class CorePatcher :
2+
IPatcher
3+
{
4+
static XNamespace cp = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
5+
static XName lastModifiedBy = cp + "lastModifiedBy";
6+
static XNamespace dcterms = "http://purl.org/dc/terms/";
7+
static XName created = dcterms + "created";
8+
static XName modified = dcterms + "modified";
9+
10+
public void PatchXml(XDocument xml)
11+
{
12+
var root = xml.Root!;
13+
root.Element(lastModifiedBy)?.Remove();
14+
root.Element(created)?.Remove();
15+
root.Element(modified)?.Remove();
16+
}
17+
18+
public bool IsMatch(Entry entry) =>
19+
entry.FullName == "docProps/core.xml";
20+
}

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.5.0</Version>
5+
<Version>0.6.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>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<dc:title>The Title</dc:title>
3+
<dc:subject />
4+
<dc:creator />
5+
<cp:keywords />
6+
<dc:description />
7+
<cp:category />
8+
</cp:coreProperties>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<dc:title>The Title</dc:title>
3+
<dc:subject />
4+
<dc:creator />
5+
<cp:keywords />
6+
<dc:description />
7+
<cp:category />
8+
</cp:coreProperties>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[TestFixture]
2+
public class CorePatcherTests
3+
{
4+
[Test]
5+
public Task Patch()
6+
{
7+
var xml =
8+
"""
9+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
10+
<cp:coreProperties
11+
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
12+
xmlns:dc="http://purl.org/dc/elements/1.1/"
13+
xmlns:dcterms="http://purl.org/dc/terms/"
14+
xmlns:dcmitype="http://purl.org/dc/dcmitype/"
15+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
16+
<dc:title>The Title</dc:title>
17+
<dc:subject />
18+
<dc:creator />
19+
<cp:keywords />
20+
<dc:description />
21+
<cp:lastModifiedBy>Simon Cropp</cp:lastModifiedBy>
22+
<dcterms:created xsi:type="dcterms:W3CDTF">2020-01-01T00:00:00Z</dcterms:created>
23+
<dcterms:modified xsi:type="dcterms:W3CDTF">2020-01-01T00:00:00Z</dcterms:modified>
24+
<cp:category />
25+
</cp:coreProperties>
26+
""";
27+
28+
var document = PatchHelper.Patch<CorePatcher>(xml);
29+
return Verify(document);
30+
}
31+
}
-87 Bytes
Binary file not shown.
-75 Bytes
Binary file not shown.
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"?><cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>The Title</dc:title><dc:subject /><dc:creator /><cp:keywords /><dc:description /><cp:lastModifiedBy>Simon Cropp</cp:lastModifiedBy><dcterms:created xsi:type="dcterms:W3CDTF">2020-01-01T00:00:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2020-01-01T00:00:00Z</dcterms:modified><cp:category /></cp:coreProperties>
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?><cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>The Title</dc:title><dc:subject /><dc:creator /><cp:keywords /><dc:description /><cp:category /></cp:coreProperties>
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"?><cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>The Title</dc:title><dc:subject /><dc:creator /><cp:keywords /><dc:description /><cp:lastModifiedBy>Simon Cropp</cp:lastModifiedBy><dcterms:created xsi:type="dcterms:W3CDTF">2020-01-01T00:00:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2020-01-01T00:00:00Z</dcterms:modified><cp:category /></cp:coreProperties>
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?><cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>The Title</dc:title><dc:subject /><dc:creator /><cp:keywords /><dc:description /><cp:category /></cp:coreProperties>

0 commit comments

Comments
 (0)