Skip to content

[System.Formats.Tar] Add deterministic TarWriter options - #132050

Closed
jetersen wants to merge 1 commit into
dotnet:mainfrom
jetersen:feature/deterministic-tar-writer
Closed

[System.Formats.Tar] Add deterministic TarWriter options#132050
jetersen wants to merge 1 commit into
dotnet:mainfrom
jetersen:feature/deterministic-tar-writer

Conversation

@jetersen

@jetersen jetersen commented Aug 9, 2026

Copy link
Copy Markdown

Fixes #132049

Summary

Adds an opt-in deterministic mode to TarWriterOptions together with explicit filesystem metadata overrides.

  • Uses stable PAX extended header names without the current process ID or temporary directory.
  • Normalizes entries created from filesystem paths to Unix epoch modification time, UID/GID 0, and empty user/group names when deterministic mode is enabled.
  • Allows callers to override modification time, UID, GID, user name, and group name independently of deterministic mode.
  • Preserves metadata explicitly set on TarEntry instances passed to WriteEntry(TarEntry).

This provides the behavior needed by deterministic archive and container-image builders without requiring them to reproduce TarWriter's internal PAX serialization.

Validation

  • Built System.Formats.Tar source and reference assemblies in Release with zero warnings and errors.
  • Compiled System.Formats.Tar.Tests for the Unix and Windows targets.
  • Ran focused behavioral validation against the changed assembly covering stable PAX names, normalized path metadata, explicit overrides, byte-identical output after source timestamp changes, and preservation of manually supplied entry metadata.

Copilot AI lite review requested due to automatic review settings August 9, 2026 10:16
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new deterministic metadata mode to System.Formats.Tar’s TarWriter via TarWriterOptions, aiming to make produced PAX archives byte-stable across runs by removing process- and host-dependent variability.

Changes:

  • Introduces TarWriterOptions.Deterministic and Override* metadata properties (mtime/uid/gid/uname/gname) and threads these settings through TarWriter’s path-based entry construction.
  • Updates PAX header-writing to generate process-independent extended/global header names when deterministic mode is enabled.
  • Adds unit tests covering option defaults, deterministic path-metadata normalization, override precedence, stable output, and PAX header name stability.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/libraries/System.Formats.Tar/tests/TarWriterOptions.Tests.cs Verifies default values and basic set/get for new TarWriterOptions properties.
src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.File.Tests.Unix.cs Adds Unix-only privileged coverage ensuring deterministic mode doesn’t capture source ownership.
src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.File.Tests.cs Adds cross-platform tests for deterministic normalization, override precedence, and byte-stable output.
src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs Adds tests validating deterministic PAX extended/global header naming and preserving explicit entry metadata.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriterOptions.cs Adds the new public options API surface with XML documentation.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs Plumbs options into the writer, passes deterministic flag into PAX header writers, and centralizes mtime override logic.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Unix.cs Applies deterministic defaults and override metadata when constructing entries from filesystem paths on Unix.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Windows.cs Applies mtime override and sets uid/gid/uname/gname defaults/overrides for path-based entries on Windows.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs Adds deterministic-aware PAX extended/global header name generation and threads the flag through write helpers.
src/libraries/System.Formats.Tar/ref/System.Formats.Tar.cs Exposes the new public API surface in the reference assembly contract.

Comment on lines 140 to +150
public sealed partial class TarWriterOptions
{
public TarWriterOptions() { }
public bool Deterministic { get { throw null; } set { } }
public System.Formats.Tar.TarEntryFormat Format { get { throw null; } set { } }
public System.Formats.Tar.TarHardLinkMode HardLinkMode { get { throw null; } set { } }
public int? OverrideGid { get { throw null; } set { } }
public string? OverrideGName { get { throw null; } set { } }
public System.DateTimeOffset? OverrideModificationTime { get { throw null; } set { } }
public int? OverrideUid { get { throw null; } set { } }
public string? OverrideUName { get { throw null; } set { } }
Comment on lines +143 to +150
public bool Deterministic { get { throw null; } set { } }
public System.Formats.Tar.TarEntryFormat Format { get { throw null; } set { } }
public System.Formats.Tar.TarHardLinkMode HardLinkMode { get { throw null; } set { } }
public int? OverrideGid { get { throw null; } set { } }
public string? OverrideGName { get { throw null; } set { } }
public System.DateTimeOffset? OverrideModificationTime { get { throw null; } set { } }
public int? OverrideUid { get { throw null; } set { } }
public string? OverrideUName { get { throw null; } set { } }
@teo-tsirpanis

Copy link
Copy Markdown
Contributor

Hello, and thanks for your contribution. According to the process, Pull Requests that add new APIs must be opened after the API gets approved, which means that I have to close this. Feel free to open a new PR after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add reproducible/deterministic mode to TarWriter for normalized metadata

3 participants