Skip to content

Commit 1fbde51

Browse files
akoeplingerjozkee
authored andcommitted
Dispose underlying stream in TarReader.DisposeAsync() as well (dotnet#79920)
* Dispose underlying stream in TarReader.DisposeAsync() as well Same as dotnet#79899 * Consolidate duplicated WrappedStream test helpers to Common sources * Dispose stream passed to WrappedStream
1 parent 08e8e19 commit 1fbde51

File tree

7 files changed

+13
-133
lines changed

7 files changed

+13
-133
lines changed

src/libraries/System.Formats.Tar/tests/WrappedStream.cs renamed to src/libraries/Common/tests/System/IO/WrappedStream.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.IO;
5-
6-
namespace System.Formats.Tar
4+
namespace System.IO
75
{
86
public class WrappedStream : Stream
97
{

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ public async ValueTask DisposeAsync()
8282
{
8383
_isDisposed = true;
8484

85-
if (!_leaveOpen && _dataStreamsToDispose?.Count > 0)
85+
if (!_leaveOpen)
8686
{
87-
foreach (Stream s in _dataStreamsToDispose)
87+
await _archiveStream.DisposeAsync().ConfigureAwait(false);
88+
89+
if (_dataStreamsToDispose?.Count > 0)
8890
{
89-
await s.DisposeAsync().ConfigureAwait(false);
91+
foreach (Stream s in _dataStreamsToDispose)
92+
{
93+
await s.DisposeAsync().ConfigureAwait(false);
94+
}
9095
}
9196
}
9297
}

src/libraries/System.Formats.Tar/tests/System.Formats.Tar.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
<Compile Include="TarWriter\TarWriter.WriteEntry.Tests.cs" />
6969
<Compile Include="TarWriter\TarWriter.WriteEntry.Entry.Ustar.Tests.cs" />
7070
<Compile Include="TarWriter\TarWriter.WriteEntry.Entry.V7.Tests.cs" />
71-
<Compile Include="WrappedStream.cs" Link="WrappedStream.cs" />
7271
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs" Link="Common\DisableRuntimeMarshalling.cs" />
7372
<Compile Include="$(CommonTestPath)System\IO\ReparsePointUtilities.cs" Link="Common\System\IO\ReparsePointUtilities.cs" />
73+
<Compile Include="$(CommonTestPath)System\IO\WrappedStream.cs" Link="Common\System\IO\WrappedStream.cs" />
7474
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
7575
</ItemGroup>
7676
<!-- Windows specific files -->

src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.LongFile.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static IEnumerable<object[]> WriteEntry_LongFileSize_TheoryData()
3030
public void WriteEntry_LongFileSize(TarEntryFormat entryFormat, long size, bool unseekableStream)
3131
{
3232
// Write archive with a 8 Gb long entry.
33-
FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
33+
using FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
3434
Stream s = unseekableStream ? new WrappedStream(tarFile, tarFile.CanRead, tarFile.CanWrite, canSeek: false) : tarFile;
3535

3636
using (TarWriter writer = new(s, leaveOpen: true))

src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.LongFile.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static IEnumerable<object[]> WriteEntry_LongFileSize_TheoryDataAsync()
2020
public async Task WriteEntry_LongFileSizeAsync(TarEntryFormat entryFormat, long size, bool unseekableStream)
2121
{
2222
// Write archive with a 8 Gb long entry.
23-
FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
23+
await using FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
2424
Stream s = unseekableStream ? new WrappedStream(tarFile, tarFile.CanRead, tarFile.CanWrite, canSeek: false) : tarFile;
2525

2626
await using (TarWriter writer = new(s, leaveOpen: true))

src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<Compile Include="CompressionStreamUnitTests.Deflate.cs" />
1818
<Compile Include="CompressionStreamUnitTests.Gzip.cs" />
1919
<Compile Include="Utilities\StripHeaderAndFooter.cs" />
20-
<Compile Include="Utilities\WrappedStream.cs" />
2120
<Compile Include="XunitAssemblyAttributes.cs" />
2221
<Compile Include="ZipArchive\zip_CreateTests.cs" />
2322
<Compile Include="ZipArchive\zip_CreateTests.Comments.cs" />
@@ -36,6 +35,7 @@
3635
<Compile Include="$(CommonTestPath)System\IO\Compression\LocalMemoryStream.cs" Link="Common\System\IO\Compression\LocalMemoryStream.cs" />
3736
<Compile Include="$(CommonTestPath)System\IO\Compression\StreamHelpers.cs" Link="Common\System\IO\Compression\StreamHelpers.cs" />
3837
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs" Link="Common\System\IO\TempFile.cs" />
38+
<Compile Include="$(CommonTestPath)System\IO\WrappedStream.cs" Link="Common\System\IO\WrappedStream.cs" />
3939
<Compile Include="$(CommonTestPath)System\IO\Compression\ZipTestHelper.cs" Link="Common\System\IO\Compression\ZipTestHelper.cs" />
4040
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
4141
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs" Link="Common\System\Threading\Tasks\TaskToApm.cs" />

src/libraries/System.IO.Compression/tests/Utilities/WrappedStream.cs

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)