Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose underlying stream in TarReader.DisposeAsync() as well #79920

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;

namespace System.Formats.Tar
namespace System.IO
{
public class WrappedStream : Stream
Copy link
Member Author

@akoeplinger akoeplinger Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlossanlop do you remember which changes you meant back in #67883 (comment) ?

It seems to work with the consolidated version.

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ public async ValueTask DisposeAsync()
{
_isDisposed = true;

if (!_leaveOpen && _dataStreamsToDispose?.Count > 0)
if (!_leaveOpen)
{
foreach (Stream s in _dataStreamsToDispose)
await _archiveStream.DisposeAsync().ConfigureAwait(false);

if (_dataStreamsToDispose?.Count > 0)
{
await s.DisposeAsync().ConfigureAwait(false);
foreach (Stream s in _dataStreamsToDispose)
{
await s.DisposeAsync().ConfigureAwait(false);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
<Compile Include="TarWriter\TarWriter.WriteEntry.Tests.cs" />
<Compile Include="TarWriter\TarWriter.WriteEntry.Entry.Ustar.Tests.cs" />
<Compile Include="TarWriter\TarWriter.WriteEntry.Entry.V7.Tests.cs" />
<Compile Include="WrappedStream.cs" Link="WrappedStream.cs" />
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs" Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonTestPath)System\IO\ReparsePointUtilities.cs" Link="Common\System\IO\ReparsePointUtilities.cs" />
<Compile Include="$(CommonTestPath)System\IO\WrappedStream.cs" Link="Common\System\IO\WrappedStream.cs" />
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
</ItemGroup>
<!-- Windows specific files -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static IEnumerable<object[]> WriteEntry_LongFileSize_TheoryData()
public void WriteEntry_LongFileSize(TarEntryFormat entryFormat, long size, bool unseekableStream)
{
// Write archive with a 8 Gb long entry.
FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
using FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
Stream s = unseekableStream ? new WrappedStream(tarFile, tarFile.CanRead, tarFile.CanWrite, canSeek: false) : tarFile;

using (TarWriter writer = new(s, leaveOpen: true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IEnumerable<object[]> WriteEntry_LongFileSize_TheoryDataAsync()
public async Task WriteEntry_LongFileSizeAsync(TarEntryFormat entryFormat, long size, bool unseekableStream)
{
// Write archive with a 8 Gb long entry.
FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
await using FileStream tarFile = File.Open(GetTestFilePath(), new FileStreamOptions { Access = FileAccess.ReadWrite, Mode = FileMode.Create, Options = FileOptions.DeleteOnClose });
Stream s = unseekableStream ? new WrappedStream(tarFile, tarFile.CanRead, tarFile.CanWrite, canSeek: false) : tarFile;

await using (TarWriter writer = new(s, leaveOpen: true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<Compile Include="CompressionStreamUnitTests.Deflate.cs" />
<Compile Include="CompressionStreamUnitTests.Gzip.cs" />
<Compile Include="Utilities\StripHeaderAndFooter.cs" />
<Compile Include="Utilities\WrappedStream.cs" />
<Compile Include="XunitAssemblyAttributes.cs" />
<Compile Include="ZipArchive\zip_CreateTests.cs" />
<Compile Include="ZipArchive\zip_CreateTests.Comments.cs" />
Expand All @@ -37,6 +36,7 @@
<Compile Include="$(CommonTestPath)System\IO\Compression\LocalMemoryStream.cs" Link="Common\System\IO\Compression\LocalMemoryStream.cs" />
<Compile Include="$(CommonTestPath)System\IO\Compression\StreamHelpers.cs" Link="Common\System\IO\Compression\StreamHelpers.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs" Link="Common\System\IO\TempFile.cs" />
<Compile Include="$(CommonTestPath)System\IO\WrappedStream.cs" Link="Common\System\IO\WrappedStream.cs" />
<Compile Include="$(CommonTestPath)System\IO\Compression\ZipTestHelper.cs" Link="Common\System\IO\Compression\ZipTestHelper.cs" />
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs" Link="Common\System\Threading\Tasks\TaskToApm.cs" />
Expand Down
123 changes: 0 additions & 123 deletions src/libraries/System.IO.Compression/tests/Utilities/WrappedStream.cs

This file was deleted.