-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/7.0] TarReader should dispose underlying stream if leaveOpen…
… is false (#80598) * TarReader should dispose underlying stream if leaveOpen is false (#79899) * Dispose underlying stream in TarReader.DisposeAsync() as well (#79920) * Dispose underlying stream in TarReader.DisposeAsync() as well Same as #79899 * Consolidate duplicated WrappedStream test helpers to Common sources * Dispose stream passed to WrappedStream * Dispose archive stream after the list of DataStreams (#80572) * Dispose archive stream after the list of DataStreams * Add tests for TarReader.DisposeAsync properly disposing underlying stream Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
- Loading branch information
1 parent
5359311
commit c8a73af
Showing
9 changed files
with
95 additions
and
138 deletions.
There are no files selected for viewing
4 changes: 1 addition & 3 deletions
4
...System.Formats.Tar/tests/WrappedStream.cs → ...s/Common/tests/System/IO/WrappedStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.Async.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace System.Formats.Tar.Tests | ||
{ | ||
public partial class TarReader_Tests : TarTestsBase | ||
{ | ||
[Fact] | ||
public async Task TarReader_LeaveOpen_False_Async() | ||
{ | ||
await using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, TestTarFormat.pax, "many_small_files"); | ||
List<Stream> dataStreams = new List<Stream>(); | ||
await using (TarReader reader = new TarReader(ms, leaveOpen: false)) | ||
{ | ||
TarEntry entry; | ||
while ((entry = await reader.GetNextEntryAsync()) != null) | ||
{ | ||
if (entry.DataStream != null) | ||
{ | ||
dataStreams.Add(entry.DataStream); | ||
} | ||
} | ||
} | ||
|
||
Assert.Throws<ObjectDisposedException>(() => ms.ReadByte()); | ||
|
||
Assert.True(dataStreams.Any()); | ||
foreach (Stream ds in dataStreams) | ||
{ | ||
Assert.Throws<ObjectDisposedException>(() => ds.ReadByte()); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task TarReader_LeaveOpen_True_Async() | ||
{ | ||
await using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, TestTarFormat.pax, "many_small_files"); | ||
List<Stream> dataStreams = new List<Stream>(); | ||
await using (TarReader reader = new TarReader(ms, leaveOpen: true)) | ||
{ | ||
TarEntry entry; | ||
while ((entry = await reader.GetNextEntryAsync()) != null) | ||
{ | ||
if (entry.DataStream != null) | ||
{ | ||
dataStreams.Add(entry.DataStream); | ||
} | ||
} | ||
} | ||
|
||
ms.ReadByte(); // Should not throw | ||
|
||
Assert.True(dataStreams.Any()); | ||
foreach (Stream ds in dataStreams) | ||
{ | ||
ds.ReadByte(); // Should not throw | ||
ds.Dispose(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 0 additions & 123 deletions
123
src/libraries/System.IO.Compression/tests/Utilities/WrappedStream.cs
This file was deleted.
Oops, something went wrong.