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

Commit 29cb502

Browse files
committed
Make it so we don't run tasks inside tasks, and instead just run one chain (so it can fail and we can catch it)
1 parent c32060d commit 29cb502

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,45 +111,51 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
111111
return;
112112
}
113113

114-
new ActionTask(cancellationToken, () => {
115-
if (IsGitExtracted())
114+
var task = new FuncTask<NPath>(cancellationToken, () =>
115+
{
116+
if (!IsGitExtracted())
116117
{
117118
Logger.Trace("SetupGitIfNeeded: Skipped");
118-
onSuccess.PreviousResult = installDetails.GitExecutablePath;
119-
onSuccess.Start();
120-
}
121-
else
122-
{
123-
ExtractPortableGit(onSuccess, onFailure);
119+
throw new Exception();
124120
}
125-
}).Start();
121+
return installDetails.GitExecutablePath;
122+
});
123+
var extractTask = ExtractPortableGit();
124+
extractTask.Then(onSuccess, TaskRunOptions.OnSuccess, taskIsTopOfChain: true);
125+
extractTask.Then(onFailure, TaskRunOptions.OnFailure, taskIsTopOfChain: true);
126+
127+
task.Then(onSuccess, TaskRunOptions.OnSuccess, taskIsTopOfChain: true);
128+
task.Then(extractTask, TaskRunOptions.OnFailure, taskIsTopOfChain: true);
129+
task.Start();
126130
}
127131

128-
private void ExtractPortableGit(ActionTask<NPath> onSuccess, ITask onFailure)
132+
private FuncTask<NPath> ExtractPortableGit()
129133
{
130-
ITask downloadFilesTask = null;
131-
if ((gitArchiveFilePath == null) || (gitLfsArchivePath == null))
132-
{
133-
downloadFilesTask = CreateDownloadTask();
134-
}
135-
136134
var tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
137135
var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
138136
var gitLfsExtractPath = tempZipExtractPath.Combine("git-lfs").CreateDirectory();
139137

140-
var resultTask = new UnzipTask(cancellationToken, gitArchiveFilePath, gitExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails.GitExtractedMD5)
141-
.Then(new UnzipTask(cancellationToken, gitLfsArchivePath, gitLfsExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails .GitLfsExtractedMD5))
142-
.Then(s => MoveGitAndLfs(gitExtractPath, gitLfsExtractPath, tempZipExtractPath));
143-
144-
resultTask.Then(onFailure, TaskRunOptions.OnFailure);
145-
resultTask.Then(onSuccess, TaskRunOptions.OnSuccess);
138+
var unzipTasks = CreateUnzipTasks(gitExtractPath, gitLfsExtractPath, tempZipExtractPath);
146139

147-
if (downloadFilesTask != null)
140+
if (gitArchiveFilePath == null || gitLfsArchivePath == null)
148141
{
149-
resultTask = downloadFilesTask.Then(resultTask);
142+
var downloadFilesTask = CreateDownloadTask();
143+
unzipTasks = downloadFilesTask.Then(unzipTasks);
150144
}
151145

152-
resultTask.Start();
146+
return unzipTasks;
147+
}
148+
149+
private FuncTask<NPath> CreateUnzipTasks(NPath gitExtractPath, NPath gitLfsExtractPath, NPath tempZipExtractPath)
150+
{
151+
var unzipGitTask = new UnzipTask(cancellationToken, gitArchiveFilePath, gitExtractPath, sharpZipLibHelper,
152+
environment.FileSystem, GitInstallDetails.GitExtractedMD5);
153+
var unzipGitLfsTask = new UnzipTask(cancellationToken, gitLfsArchivePath, gitLfsExtractPath, sharpZipLibHelper,
154+
environment.FileSystem, GitInstallDetails.GitLfsExtractedMD5);
155+
var moveGitTask = new FuncTask<NPath>(cancellationToken, () => MoveGitAndLfs(gitExtractPath, gitLfsExtractPath, tempZipExtractPath));
156+
return unzipGitTask
157+
.Then(unzipGitLfsTask)
158+
.Then(moveGitTask);
153159
}
154160

155161
private NPath MoveGitAndLfs(NPath gitExtractPath, NPath gitLfsExtractPath, NPath tempZipExtractPath)

0 commit comments

Comments
 (0)