Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 197ce5c

Browse files
committed
Get essential changes from fixes/prefer-local-resources (PR #590)
1 parent 7873cd2 commit 197ce5c

File tree

1 file changed

+49
-35
lines changed

1 file changed

+49
-35
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ class GitInstallDetails
2626

2727
private readonly bool onWindows;
2828

29-
public GitInstallDetails(NPath pluginDataPath, bool onWindows)
29+
public GitInstallDetails(NPath baseDataPath, bool onWindows)
3030
{
3131
this.onWindows = onWindows;
3232

33-
PluginDataPath = pluginDataPath;
33+
ZipPath = baseDataPath.Combine("downloads");
34+
ZipPath.EnsureDirectoryExists();
3435

35-
var gitInstallPath = PluginDataPath.Combine(PackageNameWithVersion);
36+
var gitInstallPath = baseDataPath.Combine(PackageNameWithVersion);
3637
GitInstallationPath = gitInstallPath;
3738

3839
if (onWindows)
@@ -60,7 +61,7 @@ public NPath GetGitLfsExecutablePath(NPath gitInstallRoot)
6061
: gitInstallRoot.Combine("libexec", "git-core", GitLfsExecutable);
6162
}
6263

63-
public NPath PluginDataPath { get; }
64+
public NPath ZipPath { get; }
6465
public NPath GitInstallationPath { get; }
6566
public string GitExecutable { get; }
6667
public NPath GitExecutablePath { get; }
@@ -91,9 +92,8 @@ public GitInstaller(IEnvironment environment, CancellationToken cancellationToke
9192

9293
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken,
9394
GitInstallDetails installDetails, NPath gitArchiveFilePath, NPath gitLfsArchivePath)
94-
: this(
95-
environment, ZipHelper.Instance, cancellationToken, installDetails, gitArchiveFilePath,
96-
gitLfsArchivePath)
95+
: this(environment, ZipHelper.Instance, cancellationToken, installDetails,
96+
gitArchiveFilePath, gitLfsArchivePath)
9797
{}
9898

9999
public GitInstaller(IEnvironment environment, IZipHelper sharpZipLibHelper, CancellationToken cancellationToken,
@@ -120,7 +120,10 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
120120
var isGitExtractedTask = new FuncTask<NPath>(cancellationToken, () =>
121121
{
122122
if (!IsGitExtracted())
123+
{
124+
GrabZipFromResources();
123125
return null;
126+
}
124127
Logger.Trace("SetupGitIfNeeded: Skipped");
125128
return installDetails.GitExecutablePath;
126129
});
@@ -140,6 +143,43 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
140143
isGitExtractedTask.Start();
141144
}
142145

146+
private void GrabZipFromResources()
147+
{
148+
if (gitArchiveFilePath == null || !gitArchiveFilePath.FileExists())
149+
gitArchiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
150+
if (!gitArchiveFilePath.FileExists())
151+
gitArchiveFilePath = null;
152+
153+
if (gitLfsArchivePath == null || !gitLfsArchivePath.FileExists())
154+
gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
155+
if (!gitLfsArchivePath.FileExists())
156+
gitLfsArchivePath = null;
157+
}
158+
159+
private ITask CreateDownloadTask()
160+
{
161+
gitArchiveFilePath = installDetails.ZipPath.Combine("git.zip");
162+
gitLfsArchivePath = installDetails.ZipPath.Combine("git-lfs.zip");
163+
164+
var downloader = new Downloader();
165+
downloader.QueueDownload(installDetails.GitZipUrl, installDetails.GitZipMd5Url, installDetails.ZipPath);
166+
downloader.QueueDownload(installDetails.GitLfsZipUrl, installDetails.GitLfsZipMd5Url, installDetails.ZipPath);
167+
return downloader;
168+
}
169+
170+
private FuncTask<NPath> CreateUnzipTasks(NPath gitExtractPath, NPath gitLfsExtractPath, NPath tempZipExtractPath)
171+
{
172+
var unzipGitTask = new UnzipTask(cancellationToken, gitArchiveFilePath, gitExtractPath, sharpZipLibHelper,
173+
environment.FileSystem, GitInstallDetails.GitExtractedMD5);
174+
var unzipGitLfsTask = new UnzipTask(cancellationToken, gitLfsArchivePath, gitLfsExtractPath, sharpZipLibHelper,
175+
environment.FileSystem, GitInstallDetails.GitLfsExtractedMD5);
176+
177+
var moveGitTask = new FuncTask<NPath>(cancellationToken, () => MoveGitAndLfs(gitExtractPath, gitLfsExtractPath, tempZipExtractPath));
178+
return unzipGitTask
179+
.Then(unzipGitLfsTask)
180+
.Then(moveGitTask);
181+
}
182+
143183
private FuncTask<NPath> ExtractPortableGit()
144184
{
145185
var tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
@@ -157,19 +197,6 @@ private FuncTask<NPath> ExtractPortableGit()
157197
return unzipTasks;
158198
}
159199

160-
private FuncTask<NPath> CreateUnzipTasks(NPath gitExtractPath, NPath gitLfsExtractPath, NPath tempZipExtractPath)
161-
{
162-
var unzipGitTask = new UnzipTask(cancellationToken, gitArchiveFilePath, gitExtractPath, sharpZipLibHelper,
163-
environment.FileSystem, GitInstallDetails.GitExtractedMD5);
164-
var unzipGitLfsTask = new UnzipTask(cancellationToken, gitLfsArchivePath, gitLfsExtractPath, sharpZipLibHelper,
165-
environment.FileSystem, GitInstallDetails.GitLfsExtractedMD5);
166-
167-
var moveGitTask = new FuncTask<NPath>(cancellationToken, () => MoveGitAndLfs(gitExtractPath, gitLfsExtractPath, tempZipExtractPath));
168-
return unzipGitTask
169-
.Then(unzipGitLfsTask)
170-
.Then(moveGitTask);
171-
}
172-
173200
private NPath MoveGitAndLfs(NPath gitExtractPath, NPath gitLfsExtractPath, NPath tempZipExtractPath)
174201
{
175202
var targetGitLfsExecPath = installDetails.GetGitLfsExecutablePath(gitExtractPath);
@@ -193,19 +220,6 @@ private NPath MoveGitAndLfs(NPath gitExtractPath, NPath gitLfsExtractPath, NPath
193220
return installDetails.GitExecutablePath;
194221
}
195222

196-
private ITask CreateDownloadTask()
197-
{
198-
gitArchiveFilePath = installDetails.PluginDataPath.Combine("git.zip");
199-
gitLfsArchivePath = installDetails.PluginDataPath.Combine("git-lfs.zip");
200-
201-
var downloader = new Downloader();
202-
203-
downloader.QueueDownload(installDetails.GitZipUrl, installDetails.GitZipMd5Url, installDetails.PluginDataPath);
204-
downloader.QueueDownload(installDetails.GitLfsZipUrl, installDetails.GitLfsZipMd5Url, installDetails.PluginDataPath);
205-
206-
return downloader;
207-
}
208-
209223
private bool IsGitExtracted()
210224
{
211225
if (!installDetails.GitInstallationPath.DirectoryExists())
@@ -214,7 +228,7 @@ private bool IsGitExtracted()
214228
return false;
215229
}
216230

217-
var gitExecutableMd5 = environment.FileSystem.CalculateFileMD5(installDetails.GitExecutablePath);
231+
var gitExecutableMd5 = installDetails.GitExecutablePath.CalculateMD5();
218232
var expectedGitExecutableMd5 = environment.IsWindows ? GitInstallDetails.WindowsGitExecutableMD5 : GitInstallDetails.MacGitExecutableMD5;
219233

220234
if (!expectedGitExecutableMd5.Equals(gitExecutableMd5, StringComparison.InvariantCultureIgnoreCase))
@@ -223,7 +237,7 @@ private bool IsGitExtracted()
223237
return false;
224238
}
225239

226-
var gitLfsExecutableMd5 = environment.FileSystem.CalculateFileMD5(installDetails.GitLfsExecutablePath);
240+
var gitLfsExecutableMd5 = installDetails.GitLfsExecutablePath.CalculateMD5();
227241
var expectedGitLfsExecutableMd5 = environment.IsWindows ? GitInstallDetails.WindowsGitLfsExecutableMD5 : GitInstallDetails.MacGitLfsExecutableMD5;
228242

229243
if (!expectedGitLfsExecutableMd5.Equals(gitLfsExecutableMd5, StringComparison.InvariantCultureIgnoreCase))

0 commit comments

Comments
 (0)