Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
44300eb
Throw ArgumentException on unsupported tar entry type
carlossanlop Aug 30, 2022
386ca70
Adjust tests
carlossanlop Aug 30, 2022
4c049be
Also change exception type for internal TarEntry conversion construct…
carlossanlop Aug 30, 2022
712acb5
LinkName setter null check.
carlossanlop Aug 31, 2022
785584d
Internal constructors SeekableSubReadStream and SubReadStream unseeka…
carlossanlop Aug 31, 2022
5931c6b
DataStream setter for regular file should throw ArgumentException if …
carlossanlop Aug 31, 2022
2848e80
TarFile CreateFromDirectory unwritable destination change exception t…
carlossanlop Aug 31, 2022
1647a89
Change to ArgumentException when ExtractToDirectory is an unreadable …
carlossanlop Aug 31, 2022
5216a08
Add some missing exception docs for TarEntry.
carlossanlop Aug 31, 2022
64efec2
Change TarReader constructor exception if unreadable stream. Close te…
carlossanlop Aug 31, 2022
3694af2
Change TarWriter exception for unwritable stream to ArgumentException…
carlossanlop Aug 31, 2022
bc608fc
Add missing documentation for exceptions in constructors.
carlossanlop Aug 31, 2022
b6d620c
Change wording of conversion constructors comment when passing a Pax …
carlossanlop Aug 31, 2022
9c4ccaa
Apply suggestions by Jozkee
carlossanlop Aug 31, 2022
13f52c0
Add exception to LinkName if the entry type is hard/symlink and the u…
carlossanlop Aug 31, 2022
e7d911d
Convert all FormatException to InvalidDataException
carlossanlop Aug 31, 2022
ed4ab9c
Address more suggestions
carlossanlop Aug 31, 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
Change TarWriter exception for unwritable stream to ArgumentException…
…, adjust docs and tests.
  • Loading branch information
carlossanlop committed Aug 31, 2022
commit 3694af23fc6c83828c329c1ccbc6df7d177d75e1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public sealed partial class TarWriter : IDisposable, IAsyncDisposable
/// </summary>
/// <param name="archiveStream">The stream to write to.</param>
/// <remarks>When using this constructor, <see cref="TarEntryFormat.Pax"/> is used as the default format of the entries written to the archive using the <see cref="WriteEntry(string, string?)"/> method.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="archiveStream"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="archiveStream"/> is unwritable.</exception>
public TarWriter(Stream archiveStream)
: this(archiveStream, TarEntryFormat.Pax, leaveOpen: false)
{
Expand All @@ -35,6 +37,8 @@ public TarWriter(Stream archiveStream)
/// </summary>
/// <param name="archiveStream">The stream to write to.</param>
/// <param name="leaveOpen"><see langword="false"/> to dispose the <paramref name="archiveStream"/> when this instance is disposed; <see langword="true"/> to leave the stream open.</param>
/// <exception cref="ArgumentNullException"><paramref name="archiveStream"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="archiveStream"/> is unwritable.</exception>
public TarWriter(Stream archiveStream, bool leaveOpen = false)
: this(archiveStream, TarEntryFormat.Pax, leaveOpen)
{
Expand All @@ -50,15 +54,15 @@ public TarWriter(Stream archiveStream, bool leaveOpen = false)
/// <see langword="true"/> to leave the stream open. The default is <see langword="false"/>.</param>
/// <remarks>The recommended format is <see cref="TarEntryFormat.Pax"/> for its flexibility.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="archiveStream"/> is <see langword="null"/>.</exception>
/// <exception cref="IOException"><paramref name="archiveStream"/> is unwritable.</exception>
/// <exception cref="ArgumentException"><paramref name="archiveStream"/> is unwritable.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="format"/> is either <see cref="TarEntryFormat.Unknown"/>, or not one of the other enum values.</exception>
public TarWriter(Stream archiveStream, TarEntryFormat format = TarEntryFormat.Pax, bool leaveOpen = false)
{
ArgumentNullException.ThrowIfNull(archiveStream);

if (!archiveStream.CanWrite)
{
throw new IOException(SR.IO_NotSupported_UnwritableStream);
throw new ArgumentException(SR.IO_NotSupported_UnwritableStream);
}

if (format is not TarEntryFormat.V7 and not TarEntryFormat.Ustar and not TarEntryFormat.Pax and not TarEntryFormat.Gnu)
Expand Down Expand Up @@ -210,7 +214,7 @@ private async Task ReadFileFromDiskAndWriteToArchiveStreamAsEntryAsync(string fu
/// </list>
/// </remarks>
/// <exception cref="ObjectDisposedException">The archive stream is disposed.</exception>
/// <exception cref="InvalidOperationException">The entry type of the <paramref name="entry"/> is not supported for writing.</exception>
/// <exception cref="ArgumentNullException"><paramref name="entry"/> is <see langword="null"/>.</exception>
/// <exception cref="IOException">An I/O problem occurred.</exception>
public void WriteEntry(TarEntry entry)
{
Expand Down Expand Up @@ -251,7 +255,7 @@ public void WriteEntry(TarEntry entry)
/// </list>
/// </remarks>
/// <exception cref="ObjectDisposedException">The archive stream is disposed.</exception>
/// <exception cref="InvalidOperationException">The entry type of the <paramref name="entry"/> is not supported for writing.</exception>
/// <exception cref="ArgumentNullException"><paramref name="entry"/> is <see langword="null"/>.</exception>
/// <exception cref="IOException">An I/O problem occurred.</exception>
public Task WriteEntryAsync(TarEntry entry, CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void Constructors_UnwritableStream_Throws()
{
using MemoryStream archiveStream = new MemoryStream();
using WrappedStream wrappedStream = new WrappedStream(archiveStream, canRead: true, canWrite: false, canSeek: false);
Assert.Throws<IOException>(() => new TarWriter(wrappedStream));
Assert.Throws<IOException>(() => new TarWriter(wrappedStream, TarEntryFormat.V7));
Assert.Throws<ArgumentException>(() => new TarWriter(wrappedStream));
Assert.Throws<ArgumentException>(() => new TarWriter(wrappedStream, TarEntryFormat.V7));
}

[Fact]
Expand Down