-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace System.Formats.Tar.Tests | ||
|
@@ -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() | ||
{ | ||
MemoryStream emptyData = new(0); | ||
MemoryStream output = new(); | ||
TarWriter archive = new(output, TarEntryFormat.Pax); | ||
sobczyk marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
PaxTarEntry te = new(TarEntryType.RegularFile, "zero_size") | ||
{ DataStream = emptyData }; | ||
archive.WriteEntry(te); | ||
var sizeBuffer = output.GetBuffer()[1148..(1148 + 12)]; | ||
// we expect ocal zeros | ||
byte[] expected = [0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0]; | ||
Assert.True(sizeBuffer.SequenceEqual(expected)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) :)