相关文章推荐

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

Platform: Windows 7
Symptom: zipfiles I create are not available to be moved by the os after creation until the program ends.
Analysis: When ZipFile.CreateFromDirectory(...) calls ZipFileExtensions.DoCreateEntryFromFile(archive, ...) the ZipArchiveEntry is created with the following code (~line 220):

            ZipArchiveEntry entry = compressionLevel.HasValue
                                            ? destination.CreateEntry(entryName, compressionLevel.Value)
                                            : destination.CreateEntry(entryName);

But the ZipArchiveEntry that destination.CreatEntry(...) returns is an IDisposable object that is not wrapped with a (using ...) statement. Is this a handle leak?

Regards.

changed the title ZipFile.CreateFromDirectory(...) file locked on creation. File handle leak? ZipFile.CreateFromDirectory(...) file locked after creation. File handle leak? Apr 13, 2017 static void Main() DirectoryInfo tmpDir = Directory.CreateDirectory(Guid.NewGuid().ToString("N")); File.Create(Path.Combine(tmpDir.FullName, "someFile1.txt")).Dispose(); File.Create(Path.Combine(tmpDir.FullName, "someFile2.txt")).Dispose(); string zipPath = tmpDir.FullName + ".1.zip"; ZipFile.CreateFromDirectory(tmpDir.FullName, zipPath); File.Move(zipPath, zipPath.Replace(".1.zip", ".2.zip"));

I've been able to rename/delete the created zip manually and programmatically immediate after CreateFromDirectory completes.

 
推荐文章