Skip to content

Conversation

@kasperk81
Copy link
Contributor

@kasperk81 kasperk81 commented Jan 20, 2026

fix #121819

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 20, 2026
@iremyux
Copy link
Contributor

iremyux commented Jan 21, 2026

Hello @kasperk81 , looks like we both opened PRs to implement #121819 (mine is #123427)
I didn’t realize you were already moving forward with the implementation, sorry about the overlap.

If you’d like to proceed with your changes, I’m happy to close mine and help move the review forward on this PR.

@kasperk81
Copy link
Contributor Author

This was opened before yours, so you can close it. I've these changes since nov #121819 (comment)

string fileName = "file.txt";
File.Create(Path.Join(source.Path, fileName)).Dispose();

await using MemoryStream archive = new MemoryStream();
Copy link
Contributor

@iremyux iremyux Jan 28, 2026

Choose a reason for hiding this comment

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

very minor nit - we could match the existing style by using block style await using here and through the async tests

@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we undo the change here?

private static async Task CreateFromDirectoryInternalAsync(string sourceDirectoryName, Stream destination, bool includeBaseDirectory, bool leaveOpen, CancellationToken cancellationToken)
private static async Task CreateFromDirectoryInternalAsync(string sourceDirectoryName, Stream destination, bool includeBaseDirectory, bool leaveOpen, TarEntryFormat format, CancellationToken cancellationToken)
{
VerifyCreateFromDirectoryArguments(sourceDirectoryName, destination);
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about verifying the format too?

{
ArgumentException.ThrowIfNullOrEmpty(sourceDirectoryName);
ArgumentNullException.ThrowIfNull(destination);

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also implement a fail-fast behavior for format here? (and aysnc version as well)

Copy link
Contributor

Copilot AI left a comment

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 implements new overloads for TarFile.CreateFromDirectory methods to allow specifying the TarEntryFormat parameter, addressing issue #121819. Currently, these methods only create archives in PAX format, but the underlying TarWriter supports all four tar entry formats (V7, Ustar, Pax, Gnu). These new overloads expose this existing capability to the public API.

Changes:

  • Added four new public method overloads to TarFile class that accept a TarEntryFormat parameter
  • Existing methods now delegate to the new overloads with TarEntryFormat.Pax as the default format
  • Added test helper methods for valid and invalid tar entry formats
  • Added comprehensive test coverage for all four new overloads with both valid and invalid format values

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/libraries/System.Formats.Tar/ref/System.Formats.Tar.cs Added four new public API surface signatures for the new overloads
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarFile.cs Implemented the new overloads and refactored existing methods to delegate to them with default PAX format
src/libraries/System.Formats.Tar/tests/TarTestsBase.cs Added test data helper methods for valid and invalid TarEntryFormat values
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectory.Stream.Tests.cs Added tests for sync stream overload with format parameter
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectory.File.Tests.cs Added tests for sync file overload with format parameter
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectoryAsync.Stream.Tests.cs Added tests for async stream overload with format parameter
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectoryAsync.File.Tests.cs Added tests for async file overload with format parameter

public static Task CreateFromDirectoryAsync(string sourceDirectoryName, string destinationFileName, bool includeBaseDirectory, CancellationToken cancellationToken = default)
=> CreateFromDirectoryAsync(sourceDirectoryName, destinationFileName, includeBaseDirectory, TarEntryFormat.Pax, cancellationToken);

/// <inheritdoc cref="CreateFromDirectoryAsync(string, string, bool, CancellationToken)" />
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The new format parameter should have a <param name="format"> documentation tag describing what it does. According to the documentation guidelines in docs.prompt.md, all method parameters should be documented with param tags. The description should be a noun phrase, such as "One of the enumeration values that specifies the tar entry format to use for the archive."

Suggested change
/// <inheritdoc cref="CreateFromDirectoryAsync(string, string, bool, CancellationToken)" />
/// <inheritdoc cref="CreateFromDirectoryAsync(string, string, bool, CancellationToken)" />
/// <param name="format">One of the enumeration values that specifies the tar entry format to use for the archive.</param>

Copilot uses AI. Check for mistakes.
public static void CreateFromDirectory(string sourceDirectoryName, Stream destination, bool includeBaseDirectory)
=> CreateFromDirectory(sourceDirectoryName, destination, includeBaseDirectory, TarEntryFormat.Pax);

/// <inheritdoc cref="CreateFromDirectory(string, Stream, bool)" />
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The new format parameter should have a <param name="format"> documentation tag describing what it does. According to the documentation guidelines in docs.prompt.md, all method parameters should be documented with param tags. The description should be a noun phrase, such as "One of the enumeration values that specifies the tar entry format to use for the archive."

Suggested change
/// <inheritdoc cref="CreateFromDirectory(string, Stream, bool)" />
/// <inheritdoc cref="CreateFromDirectory(string, Stream, bool)" />
/// <param name="format">One of the enumeration values that specifies the tar entry format to use for the archive.</param>

Copilot uses AI. Check for mistakes.
public static Task CreateFromDirectoryAsync(string sourceDirectoryName, Stream destination, bool includeBaseDirectory, CancellationToken cancellationToken = default)
=> CreateFromDirectoryAsync(sourceDirectoryName, destination, includeBaseDirectory, TarEntryFormat.Pax, cancellationToken);

/// <inheritdoc cref="CreateFromDirectoryAsync(string, Stream, bool, CancellationToken)" />
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The new format parameter should have a <param name="format"> documentation tag describing what it does. According to the documentation guidelines in docs.prompt.md, all method parameters should be documented with param tags. The description should be a noun phrase, such as "One of the enumeration values that specifies the tar entry format to use for the archive."

Suggested change
/// <inheritdoc cref="CreateFromDirectoryAsync(string, Stream, bool, CancellationToken)" />
/// <inheritdoc cref="CreateFromDirectoryAsync(string, Stream, bool, CancellationToken)" />
/// <param name="format">One of the enumeration values that specifies the tar entry format to use for the archive.</param>

Copilot uses AI. Check for mistakes.
Comment on lines +114 to +115
/// <inheritdoc cref="CreateFromDirectory(string, string, bool)" />
/// <exception cref="ArgumentOutOfRangeException"><paramref name="format"/> is either <see cref="TarEntryFormat.Unknown"/>, or not one of the other enum values.</exception>
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The new format parameter should have a <param name="format"> documentation tag describing what it does. According to the documentation guidelines in docs.prompt.md, all method parameters should be documented with param tags. The description should be a noun phrase, such as "One of the enumeration values that specifies the tar entry format to use for the archive."

Copilot uses AI. Check for mistakes.
@iremyux iremyux self-requested a review January 28, 2026 20:55
Copy link
Contributor

@iremyux iremyux left a comment

Choose a reason for hiding this comment

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

looks good overall - some minor comments about checks for format value

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

Labels

area-System.Formats.Tar community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add TarEntryFormat parameter to TarFile.CreateFromDirectory

4 participants