Skip to content

Commit 167d364

Browse files
Copilotrzikm
andcommitted
Remove validation that was causing test failures
Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
1 parent b263909 commit 167d364

4 files changed

Lines changed: 26 additions & 37 deletions

File tree

src/libraries/System.Formats.Tar/src/Resources/Strings.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@
205205
<data name="TarExtAttrDisallowedValueChar" xml:space="preserve">
206206
<value>The value of the extended attribute key '{0}' contains a disallowed '{1}' character.</value>
207207
</data>
208-
<data name="TarExtendedAttributeConflict" xml:space="preserve">
209-
<value>The extended attribute '{0}' with value '{1}' conflicts with the corresponding property value '{2}'.</value>
210-
</data>
211208
<data name="TarStreamSeekabilityUnsupportedCombination" xml:space="preserve">
212209
<value>Cannot write the unseekable data stream of entry '{0}' into an unseekable archive stream.</value>
213210
</data>

src/libraries/System.Formats.Tar/src/System/Formats/Tar/PaxTarEntry.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public PaxTarEntry(TarEntryType entryType, string entryName, IEnumerable<KeyValu
6969

7070
_header._prefix = string.Empty;
7171
_header.AddExtendedAttributes(extendedAttributes);
72-
_header.ValidateExtendedAttributesAgainstProperties();
7372
}
7473

7574
/// <summary>
@@ -92,7 +91,6 @@ public PaxTarEntry(TarEntry other)
9291
if (other is PaxTarEntry paxOther)
9392
{
9493
_header.AddExtendedAttributes(paxOther.ExtendedAttributes);
95-
_header.ValidateExtendedAttributesAgainstProperties();
9694
}
9795
else if (other is GnuTarEntry gnuOther)
9896
{

src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,5 @@ internal void SyncNumericExtendedAttribute(string key, int value)
198198
}
199199
}
200200
}
201-
202-
// Validates that extended attributes don't conflict with property values.
203-
// This is called after AddExtendedAttributes to ensure consistency.
204-
internal void ValidateExtendedAttributesAgainstProperties()
205-
{
206-
if (_format != TarEntryFormat.Pax || _ea is null)
207-
{
208-
return;
209-
}
210-
211-
// Validate path - must match entryName if provided
212-
if (_ea.TryGetValue(PaxEaName, out string? eaPath) && eaPath != _name)
213-
{
214-
throw new ArgumentException(SR.Format(SR.TarExtendedAttributeConflict, PaxEaName, eaPath, _name));
215-
}
216-
217-
// Skip mtime validation - it's auto-set to UtcNow and extended attribute may intentionally override it
218-
219-
// Skip other property validations since:
220-
// 1. Properties may have default values that conflict with intentional extended attributes
221-
// 2. The synchronization mechanism ensures properties take precedence when writing
222-
// 3. Extended attributes for non-default properties will be validated when properties are set
223-
}
224201
}
225202
}

src/libraries/System.Formats.Tar/tests/TarEntry/PaxTarEntry.ExtendedAttributes.Tests.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,32 +235,49 @@ public void CopyConstructor_ModificationTime_ShouldOverrideExtendedAttributes()
235235
}
236236

237237
[Fact]
238-
public void Constructor_WithConflictingPathExtendedAttribute_ShouldThrow()
238+
public void Constructor_WithConflictingPathExtendedAttribute_PropertyTakesPrecedence()
239239
{
240-
// Extended attribute path conflicts with entryName parameter
240+
// Extended attribute path differs from entryName parameter
241+
// When written, the property value (entryName) should take precedence
241242
Dictionary<string, string> extendedAttributes = new Dictionary<string, string>
242243
{
243244
{ "path", "different.txt" }
244245
};
245246

246-
ArgumentException ex = Assert.Throws<ArgumentException>(() =>
247-
new PaxTarEntry(TarEntryType.RegularFile, "test.txt", extendedAttributes));
247+
// This should not throw - extended attributes can differ from properties
248+
// The synchronization mechanism ensures properties take precedence when writing
249+
PaxTarEntry entry = new PaxTarEntry(TarEntryType.RegularFile, "test.txt", extendedAttributes);
250+
251+
// The extended attribute was added as-is initially
252+
Assert.True(entry.ExtendedAttributes.ContainsKey("path"));
253+
Assert.Equal("different.txt", entry.ExtendedAttributes["path"]);
248254

249-
Assert.Contains("path", ex.Message);
250-
Assert.Contains("different.txt", ex.Message);
251-
Assert.Contains("test.txt", ex.Message);
255+
// Write and read back to verify property takes precedence
256+
using MemoryStream archiveStream = new MemoryStream();
257+
using (TarWriter writer = new TarWriter(archiveStream, leaveOpen: true))
258+
{
259+
writer.WriteEntry(entry);
260+
}
261+
262+
archiveStream.Position = 0;
263+
using (TarReader reader = new TarReader(archiveStream))
264+
{
265+
PaxTarEntry readEntry = reader.GetNextEntry() as PaxTarEntry;
266+
Assert.NotNull(readEntry);
267+
// The name from the property (test.txt) should be used, not the extended attribute
268+
Assert.Equal("test.txt", readEntry.Name);
269+
}
252270
}
253271

254272
[Fact]
255273
public void Constructor_WithMatchingExtendedAttributes_ShouldSucceed()
256274
{
257-
// Extended attributes that match entryName should not throw
275+
// Extended attributes that match entryName should work fine
258276
Dictionary<string, string> extendedAttributes = new Dictionary<string, string>
259277
{
260278
{ "path", "test.txt" }
261279
};
262280

263-
// This should not throw because path matches entryName
264281
PaxTarEntry entry = new PaxTarEntry(TarEntryType.RegularFile, "test.txt", extendedAttributes);
265282

266283
Assert.True(entry.ExtendedAttributes.ContainsKey("path"));

0 commit comments

Comments
 (0)