Skip to content

Commit 55bb915

Browse files
committed
ProductUpgrader: copy whole upgrade application
When upgrading VFS for Git via the built-in upgrade logic, the upgrade verb will copy the upgrader application to a temporary directory, and run the upgrade app from the temporary directory. The main reason for this is so that the upgrade application can update the original application without open file handles getting in the way (and preventing the deletion of the application that is being updated). The upgrade verb currently has a hard coded list of dependencies (files) required for the upgrader application to run. This can be fragile as we need to keep this list in sync with the actual dependencies, across multiple platforms. This can easily break if the dependencies change, and we update the list of files included with the installer, but not with the upgrader application. A specific occurrence of this happened in microsoft#1144. Instead, just copy over the whole VFS for Git application directory when creating a temporary copy of the upgrader application to run. We might copy over a few additional files, but this should not cause any noticeable downsides.
1 parent d7e55d4 commit 55bb915

1 file changed

Lines changed: 14 additions & 43 deletions

File tree

GVFS/GVFS.Common/ProductUpgrader.cs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ public abstract class ProductUpgrader : IDisposable
2929

3030
private const string ToolsDirectory = "Tools";
3131
private static readonly string UpgraderToolName = GVFSPlatform.Instance.Constants.GVFSUpgraderExecutableName;
32-
private static readonly string UpgraderToolConfigFile = UpgraderToolName + ".config";
33-
private static readonly string[] UpgraderToolAndLibs =
34-
{
35-
UpgraderToolName,
36-
UpgraderToolConfigFile,
37-
"GVFS.Common.dll",
38-
"GVFS.Platform.Windows.dll",
39-
"netstandard.dll",
40-
"System.Net.Http.dll",
41-
"Newtonsoft.Json.dll",
42-
"CommandLine.dll",
43-
"NuGet.Commands.dll",
44-
"NuGet.Common.dll",
45-
"NuGet.Configuration.dll",
46-
"NuGet.Frameworks.dll",
47-
"NuGet.Packaging.Core.dll",
48-
"NuGet.Packaging.dll",
49-
"NuGet.Protocol.dll",
50-
"NuGet.Versioning.dll",
51-
"System.IO.Compression.dll"
52-
};
5332

5433
public ProductUpgrader(
5534
string currentVersion,
@@ -196,29 +175,21 @@ public virtual bool TrySetupToolsDirectory(out string upgraderToolPath, out stri
196175

197176
string currentPath = ProcessHelper.GetCurrentProcessLocation();
198177
error = null;
199-
foreach (string name in UpgraderToolAndLibs)
178+
try
200179
{
201-
string toolPath = Path.Combine(currentPath, name);
202-
string destinationPath = Path.Combine(toolsDirectoryPath, name);
203-
try
204-
{
205-
this.fileSystem.CopyFile(toolPath, destinationPath, overwrite: true);
206-
}
207-
catch (UnauthorizedAccessException e)
208-
{
209-
error = string.Join(
210-
Environment.NewLine,
211-
"File copy error - " + e.Message,
212-
$"Make sure you have write permissions to directory {toolsDirectoryPath} and run {GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm} again.");
213-
this.TraceException(e, nameof(this.TrySetupToolsDirectory), $"Error copying {toolPath} to {destinationPath}.");
214-
break;
215-
}
216-
catch (IOException e)
217-
{
218-
error = "File copy error - " + e.Message;
219-
this.TraceException(e, nameof(this.TrySetupToolsDirectory), $"Error copying {toolPath} to {destinationPath}.");
220-
break;
221-
}
180+
this.fileSystem.CopyDirectoryRecursive(currentPath, toolsDirectoryPath);
181+
}
182+
catch (UnauthorizedAccessException e)
183+
{
184+
error = string.Join(
185+
Environment.NewLine,
186+
"File copy error - " + e.Message,
187+
$"Make sure you have write permissions to directory {toolsDirectoryPath} and run {GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm} again.");
188+
}
189+
catch (IOException e)
190+
{
191+
error = "File copy error - " + e.Message;
192+
this.TraceException(e, nameof(this.TrySetupToolsDirectory), $"Error copying {currentPath} to {toolsDirectoryPath}.");
222193
}
223194

224195
if (string.IsNullOrEmpty(error))

0 commit comments

Comments
 (0)