Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tar] Fill in the file size even if the file is empty. #106409

Merged
merged 4 commits into from
Aug 23, 2024

Conversation

sobczyk
Copy link
Contributor

@sobczyk sobczyk commented Aug 14, 2024

This matches standard behavior.
See #95354

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-tar
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution. Can you please add a test based on the repro code in your issue description? #95354 (comment)

@carlossanlop
Copy link
Member

@sobczyk I see your comment in the issue:

the change is basically a one liner, the problem is that the unit tests are a bit messy I'll provide the fix today or tomorrow, and will try to do some UT, but that looked more difficult than the fix

Let me know if you have any questions or I can be of assistance. I'll be happy to help.

@sobczyk
Copy link
Contributor Author

sobczyk commented Aug 21, 2024

@carlossanlop Ok, I added the repro code as an unit test.
I was wondering whether _size field should be nullable?
I'm guessing it was 0 since older .NET did not have nullables.
If _size would be nullable the check for _dataStream would not be necessary,
though the fix would change more lines.

@sobczyk
Copy link
Contributor Author

sobczyk commented Aug 21, 2024

@dotnet-policy-service agree

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

Left a minor suggestion (disposing the test types). Otherwise looks good.

I see your test only verifies Pax, which is fine for this case. I would be surprised if the issue happens only in certain formats instead of in all of them, as the affected code lines are shared among all types.

Comment on lines 358 to 360
MemoryStream emptyData = new(0);
MemoryStream output = new();
TarWriter archive = new(output, TarEntryFormat.Pax);
Copy link
Member

Choose a reason for hiding this comment

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

Did you only see the problem in Pax, or is this the only format that you tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one I tested, but the problem would apply equally to all, since small sizes are encoded the same way.

@carlossanlop
Copy link
Member

@carlossanlop Ok, I added the repro code as an unit test. I was wondering whether _size field should be nullable? I'm guessing it was 0 since older .NET did not have nullables. If _size would be nullable the check for _dataStream would not be necessary, though the fix would change more lines.

It was not nullable on purpose. I don't recall the specific reasons at the moment but this was intended. System.Formats.Tar was introduced in .NET 7. Nullables already existed in that version, so that was not the reason.

Co-authored-by: Carlos Sánchez López <[email protected]>
@sobczyk
Copy link
Contributor Author

sobczyk commented Aug 23, 2024

Is the code OK?

@carlossanlop
Copy link
Member

Is the code OK?

Yes. I was just waiting for the CI to finish.

The failure is known and pre-existing: #104905

Ready to merge. Thank you for your contribution, @sobczyk!

@carlossanlop carlossanlop merged commit 06f71f0 into dotnet:main Aug 23, 2024
82 of 84 checks passed
@@ -350,5 +351,20 @@ private int GetChecksumForFormatSpecificFields(TarEntry entry, TarEntryFormat fo
// Gnu BlockDevice: 623 + 1004 + 686 + 1142 = 3455
return checksum;
}

[Fact]
void Verify_Size_RegularFile_Empty()
Copy link
Member

Choose a reason for hiding this comment

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

nit: the test methods should be public

Copy link
Member

Choose a reason for hiding this comment

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

Yup, for consistency and repo conventions. However, it is known to work with xunit: xunit/xunit#2438 (reply in thread) :)

@am11
Copy link
Member

am11 commented Sep 10, 2024

Will it be included in .NET 9?

@carlossanlop
Copy link
Member

It's only in main right now. But we could consider requesting approval for backporting to RC2.

@carlossanlop
Copy link
Member

Did you encounter a case where you need it, @am11?

@am11
Copy link
Member

am11 commented Sep 10, 2024

If it is going in GA release, that would be nice. I haven't stumbled upon it, but I was thinking about implementing an msbuild task based on System.Formats.Tar (to replace dotnet/arcade#15038 (comment)), so I thought of checking up on the status of (this relatively new lib) support. :)

@carlossanlop
Copy link
Member

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10797621721

@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

5 participants