mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 12:30:50 +01:00
Ensure the ArchiveIterator disposes of the compression stream. Removed unused constructors.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
e6da7045b6
commit
5314da7e29
@ -64,13 +64,13 @@ namespace XenCenterLib.Archive
|
||||
if (archiveType == Type.Tar)
|
||||
return new SharpZipTarArchiveIterator(packagedData);
|
||||
if (archiveType == Type.TarGz)
|
||||
return new SharpZipTarArchiveIterator(CompressionFactory.Reader(CompressionFactory.Type.Gz, packagedData));
|
||||
return new SharpZipTarArchiveIterator(packagedData, CompressionFactory.Type.Gz);
|
||||
if (archiveType == Type.TarBz2)
|
||||
return new SharpZipTarArchiveIterator(CompressionFactory.Reader(CompressionFactory.Type.Bz2, packagedData));
|
||||
return new SharpZipTarArchiveIterator(packagedData, CompressionFactory.Type.Bz2);
|
||||
if (archiveType == Type.Zip)
|
||||
return new DotNetZipZipIterator(packagedData);
|
||||
|
||||
throw new NotSupportedException(String.Format("Type: {0} is not supported by ArchiveIterator", archiveType));
|
||||
throw new NotSupportedException($"Type {archiveType} is not supported by ArchiveIterator");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,7 +87,7 @@ namespace XenCenterLib.Archive
|
||||
if (archiveType == Type.Zip)
|
||||
return new DotNetZipZipWriter(targetPackage);
|
||||
|
||||
throw new NotSupportedException( String.Format( "Type: {0} is not supported by ArchiveWriter", archiveType ) );
|
||||
throw new NotSupportedException($"Type {archiveType} is not supported by ArchiveWriter");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ICSharpCode.SharpZipLib.Tar;
|
||||
using XenCenterLib.Compression;
|
||||
|
||||
namespace XenCenterLib.Archive
|
||||
{
|
||||
@ -39,13 +40,21 @@ namespace XenCenterLib.Archive
|
||||
public class SharpZipTarArchiveIterator : ArchiveIterator
|
||||
{
|
||||
private TarInputStream tarStream;
|
||||
private CompressionStream compressionStream;
|
||||
private TarEntry tarEntry;
|
||||
private bool disposed;
|
||||
|
||||
public SharpZipTarArchiveIterator()
|
||||
public SharpZipTarArchiveIterator(Stream compressedTarFile, CompressionFactory.Type compressionType)
|
||||
{
|
||||
tarStream = null;
|
||||
disposed = true;
|
||||
if (compressionType == CompressionFactory.Type.Gz)
|
||||
compressionStream = CompressionFactory.Reader(CompressionFactory.Type.Gz, compressedTarFile);
|
||||
else if (compressionType == CompressionFactory.Type.Bz2)
|
||||
compressionStream = CompressionFactory.Reader(CompressionFactory.Type.Bz2, compressedTarFile);
|
||||
else
|
||||
throw new NotSupportedException($"Type {compressionType} is not supported by ArchiveIterator");
|
||||
|
||||
tarStream = new TarInputStream(compressionStream);
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
public SharpZipTarArchiveIterator(Stream tarFile)
|
||||
@ -122,8 +131,8 @@ namespace XenCenterLib.Archive
|
||||
{
|
||||
if(!disposed)
|
||||
{
|
||||
if (tarStream != null)
|
||||
tarStream.Dispose();
|
||||
tarStream?.Dispose();
|
||||
compressionStream?.Dispose();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
@ -43,14 +43,10 @@ namespace XenCenterLib.Archive
|
||||
private const long bufferSize = 32*1024;
|
||||
protected bool disposed;
|
||||
|
||||
public SharpZipTarArchiveWriter()
|
||||
{
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
public SharpZipTarArchiveWriter(Stream outputStream) : this()
|
||||
public SharpZipTarArchiveWriter(Stream outputStream)
|
||||
{
|
||||
tar = new TarOutputStream(outputStream);
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
public override void SetBaseStream(Stream outputStream)
|
||||
|
@ -49,8 +49,9 @@ namespace XenCenterLib.Archive
|
||||
public event Action<long, long> CurrentFileExtractProgressChanged;
|
||||
public event Action CurrentFileExtractCompleted;
|
||||
|
||||
public DotNetZipZipIterator()
|
||||
public DotNetZipZipIterator(Stream inputStream)
|
||||
{
|
||||
Initialise(inputStream);
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
@ -73,11 +74,6 @@ namespace XenCenterLib.Archive
|
||||
}
|
||||
}
|
||||
|
||||
public DotNetZipZipIterator(Stream inputStream) : this()
|
||||
{
|
||||
Initialise(inputStream);
|
||||
}
|
||||
|
||||
private void Initialise(Stream zipStream)
|
||||
{
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user