mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 15:29:26 +01:00
Ensure we always dispose of the ArchiveIterator and ArchiveWriter after use.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
38fcc83874
commit
e6da7045b6
@ -298,18 +298,18 @@ namespace XenAdmin.Wizards.ImportWizard
|
||||
private string GetXmlStringFromTarXVA()
|
||||
{
|
||||
using (Stream stream = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
ArchiveIterator iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Tar, stream);
|
||||
if( iterator.HasNext() )
|
||||
{
|
||||
Stream ofs = new MemoryStream();
|
||||
iterator.ExtractCurrentFile(ofs);
|
||||
return new StreamReader(ofs).ReadToEnd();
|
||||
}
|
||||
{
|
||||
using (var iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Tar, stream))
|
||||
if (iterator.HasNext())
|
||||
{
|
||||
Stream ofs = new MemoryStream();
|
||||
iterator.ExtractCurrentFile(ofs);
|
||||
return new StreamReader(ofs).ReadToEnd();
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private ulong GetTotalSizeFromXmlXva(string xmlString)
|
||||
{
|
||||
|
@ -48,10 +48,8 @@ namespace XenAdminTests.ArchiveTests
|
||||
string target = TestUtils.GetTestResource("emptyfile.bz2");
|
||||
|
||||
using (var ms = new MemoryStream(File.ReadAllBytes(target)))
|
||||
{
|
||||
var iterator = ArchiveFactory.Reader((ArchiveFactory.Type)archiveType, ms);
|
||||
using (var iterator = ArchiveFactory.Reader((ArchiveFactory.Type)archiveType, ms))
|
||||
return iterator.GetType();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -62,8 +60,8 @@ namespace XenAdminTests.ArchiveTests
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var writer = ArchiveFactory.Writer((ArchiveFactory.Type)archiveType, ms);
|
||||
return writer.GetType();
|
||||
using (var writer = ArchiveFactory.Writer((ArchiveFactory.Type)archiveType, ms))
|
||||
return writer.GetType();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,17 +183,17 @@ namespace XenAdmin.Actions
|
||||
private void ExtractFile()
|
||||
{
|
||||
ArchiveIterator iterator = null;
|
||||
DotNetZipZipIterator zipIterator = null;
|
||||
|
||||
try
|
||||
{
|
||||
using (Stream stream = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Zip, stream);
|
||||
DotNetZipZipIterator zipIterator = iterator as DotNetZipZipIterator;
|
||||
zipIterator = iterator as DotNetZipZipIterator;
|
||||
|
||||
if (zipIterator != null)
|
||||
{
|
||||
zipIterator.CurrentFileExtractProgressChanged +=
|
||||
archiveIterator_CurrentFileExtractProgressChanged;
|
||||
}
|
||||
zipIterator.CurrentFileExtractProgressChanged += archiveIterator_CurrentFileExtractProgressChanged;
|
||||
|
||||
while (iterator.HasNext())
|
||||
{
|
||||
@ -215,16 +215,10 @@ namespace XenAdmin.Actions
|
||||
PatchPath = path;
|
||||
|
||||
log.InfoFormat("Update file extracted to '{0}'", path);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zipIterator != null)
|
||||
{
|
||||
zipIterator.CurrentFileExtractProgressChanged -= archiveIterator_CurrentFileExtractProgressChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -234,6 +228,9 @@ namespace XenAdmin.Actions
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (zipIterator != null)
|
||||
zipIterator.CurrentFileExtractProgressChanged -= archiveIterator_CurrentFileExtractProgressChanged;
|
||||
|
||||
if (iterator != null)
|
||||
iterator.Dispose();
|
||||
|
||||
|
@ -216,20 +216,19 @@ namespace XenAdmin.Actions
|
||||
var fi = new FileInfo(tmpFile);
|
||||
log.DebugFormat("Progress of the action until exception: {0}", PercentComplete);
|
||||
log.DebugFormat("Size file exported until exception: {0}", fi.Length);
|
||||
|
||||
try
|
||||
{
|
||||
using (Stream stream = new FileStream(tmpFile, FileMode.Open, FileAccess.Read))
|
||||
using (var iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Tar, stream))
|
||||
{
|
||||
ArchiveIterator iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Tar,
|
||||
stream);
|
||||
while (iterator.HasNext())
|
||||
{
|
||||
log.DebugFormat("Tar entry: {0} {1}", iterator.CurrentFileName(), iterator.CurrentFileSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
log.DebugFormat("Deleting {0}", tmpFile);
|
||||
File.Delete(tmpFile);
|
||||
throw new Exception(Description);
|
||||
|
Loading…
Reference in New Issue
Block a user