Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ac4d898
ref: Conversion constructors
carlossanlop Jun 1, 2022
9899220
src: Conversion constructors
carlossanlop Jun 7, 2022
476bec1
tests: Conversion constructors
carlossanlop Jun 7, 2022
4484202
src: Conversion constructor should call this instead of base
carlossanlop Jun 7, 2022
45d87a0
tests: Verify unseekable stream data can be read after conversion
carlossanlop Jun 7, 2022
adf074e
Adjust _readerOfOrigin nullability in constructors.
carlossanlop Jun 7, 2022
c9002d1
Move most constructor work to the base class.
carlossanlop Jun 7, 2022
42a000d
ref: Move TarFormat from TarReader to TarEntry
carlossanlop Jun 7, 2022
ac7ff62
ref: Move Format property from TarReader to TarEntry
carlossanlop Jun 7, 2022
a0a2d88
src: Move Format property from TarReader to TarEntry
carlossanlop Jun 7, 2022
0a54727
tests: Move Format property from TarReader to TarEntry
carlossanlop Jun 7, 2022
6de8f40
nit - Remove extra spacing in tests
carlossanlop Jun 7, 2022
b6f75cb
src: When converting, only transfer fields available in the new format.
carlossanlop Jun 9, 2022
2daa87e
tests: Verify only supported fields are transferred when converting.
carlossanlop Jun 9, 2022
247af82
Revert internal->private for magic and version
carlossanlop Jun 9, 2022
270403c
Add boolean arg to PaxTarEntry method that adds atime and ctime
carlossanlop Jun 9, 2022
d405d4e
Make sure back and forth tests create firstt timestamp with a slight …
carlossanlop Jun 9, 2022
7e79e57
Make _readerOfOrigin private again
carlossanlop Jun 9, 2022
ba4d394
src: Use UtcNow, not Now
carlossanlop Jun 9, 2022
e37c645
tests: Use UtcNow, not Now. Compare converted DateTimeOffset from dou…
carlossanlop Jun 9, 2022
f987f77
Address feedback for comments.
carlossanlop Jun 11, 2022
cd66da4
Add asserts that verify mtime has a non-default value when it is expe…
carlossanlop Jun 11, 2022
c61ce71
Adress feedback for setting field values in PosixTarEntry and TarEntr…
carlossanlop Jun 11, 2022
0a39b22
Remove code that reads atime and ctime from extended attributes and s…
carlossanlop Jun 11, 2022
948b3d7
Make sure that extended attributes always have an atime and a ctime w…
carlossanlop Jun 11, 2022
131608f
Address feedback around timestamps in tests.
carlossanlop Jun 11, 2022
1b82298
Add more tests for expected values in extended attributes after writi…
carlossanlop Jun 11, 2022
ed5ec9a
Reuse code for conversion tests.
carlossanlop Jun 13, 2022
c82f766
Change test comparisons of Assert.True with ">=" to use AssertExtensi…
carlossanlop Jun 13, 2022
98e6191
Reduce number of dictionary newing, only do it when the contents are …
carlossanlop Jun 13, 2022
b7c1c83
Avoid returning dateTimeOffset != default, instead return true on suc…
carlossanlop Jun 13, 2022
83888ba
Remove redundant assignment of format to header.
carlossanlop Jun 13, 2022
e958afd
Pass Dictionary<string,string> directly to make use of non-virtual Tr…
carlossanlop Jun 13, 2022
81376fe
Add tests that verify the default writer format is utilized when call…
carlossanlop Jun 13, 2022
b865bf4
Add overload that takes long for converting number of seconds to Date…
carlossanlop Jun 13, 2022
c37e9e7
Address latest suggestions by eerhardt
carlossanlop Jun 15, 2022
526b55a
Make sure dictionary is initialized once in PaxTarEntry constructor.
carlossanlop Jun 16, 2022
2b3dff3
Reuse code for single conversion construction tests and back-n-forth …
carlossanlop Jun 16, 2022
f10d0bf
Invert verification of default case and TarEntryFormat.Unknown in swi…
carlossanlop Jun 20, 2022
a363c3f
Change "if dictionary is not null" to "Debug.Assert "dictionary is no…
carlossanlop Jun 20, 2022
cedf1a2
Conversion tests should also check expected values of ATime and CTime…
carlossanlop Jun 20, 2022
30261f3
Chop long comment, remove another 'preferred default'.
carlossanlop Jun 20, 2022
f23d244
Make unseekable conversion tests theories to verify all writer formats.
carlossanlop Jun 20, 2022
4e3e4a3
Set _prefix to Empty if other is not ustar or pax
carlossanlop Jun 20, 2022
2d503fc
Rename TarWriter archiveFormat parameter to format
carlossanlop Jun 20, 2022
411aefa
Compare datetime offsets only up to seconds
carlossanlop Jun 20, 2022
767a5e8
Increase fixed point format specifier precision, use test comparison …
carlossanlop Jun 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reuse code for conversion tests.
  • Loading branch information
carlossanlop committed Jun 20, 2022
commit ed5ec9aa40994a35c51d5367cf0a4b1de624c74c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<ItemGroup>
<Compile Include="$(CommonTestPath)System\IO\TempDirectory.cs" Link="Common\System\IO\TempDirectory.cs" />
<Compile Include="CompressedTar.Tests.cs" />
<Compile Include="TarEntry\TarEntry.Conversion.Tests.Base.cs" />
<Compile Include="TarEntry\GnuTarEntry.Conversion.Tests.cs" />
<Compile Include="TarEntry\PaxTarEntry.Conversion.Tests.cs" />
<Compile Include="TarEntry\UstarTarEntry.Conversion.Tests.cs" />
<Compile Include="TarEntry\V7TarEntry.Conversion.Tests.cs" />
<Compile Include="TarEntry\TarEntryV7.Tests.cs" />
<Compile Include="TarEntry\TarEntryUstar.Tests.cs" />
<Compile Include="TarEntry\TarEntryPax.Tests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace System.Formats.Tar.Tests
{
public class GnuTarEntry_Conversion_Tests : TarTestsConversionBase
{
[Fact]
public void Constructor_ConversionFromV7()
{
V7TarEntry v7 = new V7TarEntry(TarEntryType.V7RegularFile, InitialEntryName);
GnuTarEntry convertedV7 = new GnuTarEntry(other: v7);

Assert.Equal(TarEntryType.RegularFile, convertedV7.EntryType);
Assert.Equal(InitialEntryName, convertedV7.Name);
}

[Fact]
public void Constructor_ConversionFromUstar()
{
UstarTarEntry ustar = new UstarTarEntry(TarEntryType.RegularFile, InitialEntryName);
GnuTarEntry convertedUstar = new GnuTarEntry(other: ustar);

Assert.Equal(TarEntryType.RegularFile, convertedUstar.EntryType);
Assert.Equal(InitialEntryName, convertedUstar.Name);
}

[Fact]
public void Constructor_ConversionFromPax()
{
PaxTarEntry pax = new PaxTarEntry(TarEntryType.RegularFile, InitialEntryName);
GnuTarEntry convertedPax = new GnuTarEntry(other: pax);

Assert.Equal(TarEntryType.RegularFile, convertedPax.EntryType);
Assert.Equal(InitialEntryName, convertedPax.Name);
}

[Fact]
public void Constructor_ConversionFromV7_From_UnseekableTarReader()
{
using MemoryStream source = GetTarMemoryStream(CompressionMethod.Uncompressed, TestTarFormat.v7, "file");
using WrappedStream wrappedSource = new WrappedStream(source, canRead: true, canWrite: false, canSeek: false);

using TarReader sourceReader = new TarReader(wrappedSource, leaveOpen: true);
V7TarEntry v7Entry = sourceReader.GetNextEntry(copyData: false) as V7TarEntry;
GnuTarEntry gnuEntry = new GnuTarEntry(other: v7Entry); // Convert, and avoid advancing wrappedSource position

using MemoryStream destination = new MemoryStream();
using (TarWriter writer = new TarWriter(destination, TarEntryFormat.Gnu, leaveOpen: true))
{
writer.WriteEntry(gnuEntry); // Write DataStream exactly where the wrappedSource position was left
}

destination.Position = 0; // Rewind
using (TarReader destinationReader = new TarReader(destination, leaveOpen: false))
{
GnuTarEntry resultEntry = destinationReader.GetNextEntry() as GnuTarEntry;
Assert.NotNull(resultEntry);
using (StreamReader streamReader = new StreamReader(resultEntry.DataStream))
{
Assert.Equal("Hello file", streamReader.ReadToEnd());
}
}
}

[Fact]
public void Constructor_ConversionFromUstar_From_UnseekableTarReader()
{
using MemoryStream source = GetTarMemoryStream(CompressionMethod.Uncompressed, TestTarFormat.ustar, "file");
using WrappedStream wrappedSource = new WrappedStream(source, canRead: true, canWrite: false, canSeek: false);

using TarReader sourceReader = new TarReader(wrappedSource, leaveOpen: true);
UstarTarEntry ustarEntry = sourceReader.GetNextEntry(copyData: false) as UstarTarEntry;
GnuTarEntry gnuEntry = new GnuTarEntry(other: ustarEntry); // Convert, and avoid advancing wrappedSource position

using MemoryStream destination = new MemoryStream();
using (TarWriter writer = new TarWriter(destination, TarEntryFormat.Gnu, leaveOpen: true))
{
writer.WriteEntry(gnuEntry); // Write DataStream exactly where the wrappedSource position was left
}

destination.Position = 0; // Rewind
using (TarReader destinationReader = new TarReader(destination, leaveOpen: false))
{
GnuTarEntry resultEntry = destinationReader.GetNextEntry() as GnuTarEntry;
Assert.NotNull(resultEntry);
using (StreamReader streamReader = new StreamReader(resultEntry.DataStream))
{
Assert.Equal("Hello file", streamReader.ReadToEnd());
}
}
}

[Fact]
public void Constructor_ConversionFromPax_From_UnseekableTarReader()
{
using MemoryStream source = GetTarMemoryStream(CompressionMethod.Uncompressed, TestTarFormat.pax, "file");
using WrappedStream wrappedSource = new WrappedStream(source, canRead: true, canWrite: false, canSeek: false);

using TarReader sourceReader = new TarReader(wrappedSource, leaveOpen: true);
PaxTarEntry paxEntry = sourceReader.GetNextEntry(copyData: false) as PaxTarEntry;
GnuTarEntry gnuEntry = new GnuTarEntry(other: paxEntry); // Convert, and avoid advancing wrappedSource position

using MemoryStream destination = new MemoryStream();
using (TarWriter writer = new TarWriter(destination, TarEntryFormat.Gnu, leaveOpen: true))
{
writer.WriteEntry(gnuEntry); // Write DataStream exactly where the wrappedSource position was left
}

destination.Position = 0; // Rewind
using (TarReader destinationReader = new TarReader(destination, leaveOpen: false))
{
GnuTarEntry resultEntry = destinationReader.GetNextEntry() as GnuTarEntry;
Assert.NotNull(resultEntry);
using (StreamReader streamReader = new StreamReader(resultEntry.DataStream))
{
Assert.Equal("Hello file", streamReader.ReadToEnd());
}
}
}

[Fact]
public void Constructor_ConversionV7_BackAndForth_RegularFile() =>
TestConstructionConversion(TarEntryType.RegularFile, TarEntryFormat.Gnu, TarEntryFormat.V7);

[Fact]
public void Constructor_ConversionUstar_BackAndForth_RegularFile() =>
TestConstructionConversion(TarEntryType.RegularFile, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_RegularFile() =>
TestConstructionConversion(TarEntryType.RegularFile, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_RegularFile() =>
TestConstructionConversion(TarEntryType.RegularFile, TarEntryFormat.Gnu, TarEntryFormat.Gnu);

[Fact]
public void Constructor_ConversionV7_BackAndForth_Directory() =>
TestConstructionConversion(TarEntryType.Directory, TarEntryFormat.Gnu, TarEntryFormat.V7);

[Fact]
public void Constructor_ConversionUstar_BackAndForth_Directory() =>
TestConstructionConversion(TarEntryType.Directory, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_Directory() =>
TestConstructionConversion(TarEntryType.Directory, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_Directory() =>
TestConstructionConversion(TarEntryType.Directory, TarEntryFormat.Gnu, TarEntryFormat.Gnu);

[Fact]
public void Constructor_ConversionV7_BackAndForth_SymbolicLink() =>
TestConstructionConversion(TarEntryType.SymbolicLink, TarEntryFormat.Gnu, TarEntryFormat.V7);

[Fact]
public void Constructor_ConversionUstar_BackAndForth_SymbolicLink() =>
TestConstructionConversion(TarEntryType.SymbolicLink, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_SymbolicLink() =>
TestConstructionConversion(TarEntryType.SymbolicLink, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_SymbolicLink() =>
TestConstructionConversion(TarEntryType.SymbolicLink, TarEntryFormat.Gnu, TarEntryFormat.Gnu);

[Fact]
public void Constructor_ConversionV7_BackAndForth_HardLink() =>
TestConstructionConversion(TarEntryType.HardLink, TarEntryFormat.Gnu, TarEntryFormat.V7);

[Fact]
public void Constructor_ConversionUstar_BackAndForth_HardLink() =>
TestConstructionConversion(TarEntryType.HardLink, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_HardLink() =>
TestConstructionConversion(TarEntryType.HardLink, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_HardLink() =>
TestConstructionConversion(TarEntryType.HardLink, TarEntryFormat.Gnu, TarEntryFormat.Gnu);

// BlockDevice, CharacterDevice and Fifo are not supported by V7

[Fact]
public void Constructor_ConversionUstar_BackAndForth_BlockDevice() =>
TestConstructionConversion(TarEntryType.BlockDevice, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_BlockDevice() =>
TestConstructionConversion(TarEntryType.BlockDevice, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_BlockDevice() =>
TestConstructionConversion(TarEntryType.BlockDevice, TarEntryFormat.Gnu, TarEntryFormat.Gnu);

[Fact]
public void Constructor_ConversionUstar_BackAndForth_CharacterDevice() =>
TestConstructionConversion(TarEntryType.CharacterDevice, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_CharacterDevice() =>
TestConstructionConversion(TarEntryType.CharacterDevice, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_CharacterDevice() =>
TestConstructionConversion(TarEntryType.CharacterDevice, TarEntryFormat.Gnu, TarEntryFormat.Gnu);

[Fact]
public void Constructor_ConversionUstar_BackAndForth_Fifo() =>
TestConstructionConversion(TarEntryType.Fifo, TarEntryFormat.Gnu, TarEntryFormat.Ustar);

[Fact]
public void Constructor_ConversionPax_BackAndForth_Fifo() =>
TestConstructionConversion(TarEntryType.Fifo, TarEntryFormat.Gnu, TarEntryFormat.Pax);

[Fact]
public void Constructor_ConversionGnu_BackAndForth_Fifo() =>
TestConstructionConversion(TarEntryType.Fifo, TarEntryFormat.Gnu, TarEntryFormat.Gnu);
}
}
Loading