From 579018272756925d885007657a9284af3634ba1c Mon Sep 17 00:00:00 2001 From: "Eric St. John" Date: Mon, 13 Jun 2016 14:06:05 -0700 Subject: [PATCH] Remove File.Copy optimization during expansion Previously we'd keep track of any file that we extracted once and try to reuse that file (by copying it) if we needed the same file later at a different destination. The reason was that it's theoretically faster to a file copy than a createfile and write, since the copy can happen entirely in the kernel. In practice we were foiled by AV scanners. This happens to be the only time during extraction where we let a file close after writing it and then try and use it again. Sure enough on fast machines we were seeing that as soon as we closed it MsMpEng would map the file for exclusive access causing our copy to fail with a sharing violation. To fix this, I've removed the copy optimization and will just copy the file from the in-memory archive every time. --- src/Microsoft.DotNet.Archive/IndexedArchive.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Microsoft.DotNet.Archive/IndexedArchive.cs b/src/Microsoft.DotNet.Archive/IndexedArchive.cs index 6e5e81030..a2847f7fc 100644 --- a/src/Microsoft.DotNet.Archive/IndexedArchive.cs +++ b/src/Microsoft.DotNet.Archive/IndexedArchive.cs @@ -238,7 +238,7 @@ namespace Microsoft.DotNet.Archive private class ExtractSource { private string _entryName; - private string _localPath; + private readonly string _localPath; private ThreadLocalZipArchive _archive; public ExtractSource(string sourceString, Dictionary externalFiles, ThreadLocalZipArchive archive) @@ -271,20 +271,9 @@ namespace Microsoft.DotNet.Archive } else { - // we open the archive each time since ZipArchive is not thread safe and we want to be able - // to extract from many threads - //using (var archive = new ZipArchive(File.Open(_archivePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))) using (var sourceStream = _archive.Archive.GetEntry(_entryName).Open()) { sourceStream.CopyTo(destinationStream); - - var destinationFileStream = destinationStream as FileStream; - if (destinationFileStream != null) - { - // Set Local path so that the next copy operation using the same source will - // do a copy instead of a write. - _localPath = destinationFileStream.Name; - } } }