Permalink
Browse files

Fixed problem with stream not being closed.

  • Loading branch information...
petterlabraaten committed Apr 3, 2017
1 parent 490fcf5 commit 4c10a6fd204a430b3afef3d5a9bb7a0b212c4d28
@@ -177,5 +177,9 @@ public override string ToString()
{
return this.GetFullName();
}
+
+ public void Dispose()
+ {
+ }
}
}
@@ -188,5 +188,9 @@ IEnumerator IEnumerable.GetEnumerator()
}
#endregion
+
+ public void Dispose()
+ {
+ }
}
}
@@ -7,7 +7,7 @@
namespace NuGetPe
{
- public class ZipPackage : IPackage
+ public class ZipPackage : IPackage, IDisposable
{
private const string AssemblyReferencesDir = "lib";
private const string ResourceAssemblyExtension = ".resources.dll";
@@ -45,7 +45,7 @@ public ZipPackage(string filePath)
//just try read
return File.Open(filePath, FileMode.Open,FileAccess.Read);
}
-
+
};
EnsureManifest();
}
@@ -131,7 +131,7 @@ public bool IsLatestVersion
private DateTimeOffset? _lastUpdated;
public DateTimeOffset LastUpdated
{
- get
+ get
{
if (_lastUpdated == null)
{
@@ -144,7 +144,7 @@ public DateTimeOffset LastUpdated
private long? _packageSize;
public long PackageSize
{
- get
+ get
{
if (_packageSize == null)
{
@@ -195,9 +195,14 @@ where IsAssemblyReference(part)
public IEnumerable<FrameworkAssemblyReference> FrameworkAssemblies { get; set; }
+ // Keep a list of open stream here, and close on dispose.
+ private List<IDisposable> _danglingStreams = new List<IDisposable>();
+
public IEnumerable<IPackageFile> GetFiles()
{
- Package package = Package.Open(_streamFactory()); // should not close
+ Stream stream = _streamFactory();
+ Package package = Package.Open(stream); // should not close
+ _danglingStreams.Add(stream); // clean up on dispose
return (from part in package.GetParts()
where IsPackageFile(part)
@@ -292,5 +297,10 @@ public override string ToString()
{
return this.GetFullName();
}
+
+ public void Dispose()
+ {
+ _danglingStreams.ForEach(ds => ds.Dispose());
+ }
}
}
@@ -443,6 +443,7 @@ private void CloseMenuItem_Click(object sender, ExecutedRoutedEventArgs e)
return;
}
+ (DataContext as PackageViewModel)?.Dispose();
DataContext = null;
}
@@ -184,5 +184,9 @@ public Version MinClientVersion
}
#endregion
+
+ public void Dispose()
+ {
+ }
}
}
@@ -266,6 +266,7 @@ public PackageFolder RootFolder
public void Dispose()
{
RootFolder.Dispose();
+ _package.Dispose();
}
#endregion
@@ -5,7 +5,7 @@
namespace NuGetPe
{
- public interface IPackage : IPackageMetadata, IServerPackageMetadata
+ public interface IPackage : IPackageMetadata, IServerPackageMetadata, IDisposable
{
bool IsAbsoluteLatestVersion { get; }

0 comments on commit 4c10a6f

Please sign in to comment.