@@ -12,13 +12,17 @@ class PortableGitInstallDetails
12
12
public NPath GitLfsExecPath { get ; }
13
13
14
14
public const string ExtractedMD5 = "65fd0575d3b47d8207b9e19d02faca4f" ;
15
+ public const string FileListMD5 = "a152a216b2e76f6c127053251187a278" ;
15
16
16
- private const string ExpectedVersion = "f02737a78695063deace08e96d5042710d3e32db" ;
17
+ private const string PackageVersion = "f02737a78695063deace08e96d5042710d3e32db" ;
17
18
private const string PackageName = "PortableGit" ;
18
- private const string PackageNameWithVersion = PackageName + "_" + ExpectedVersion ;
19
+ private const string PackageNameWithVersion = PackageName + "_" + PackageVersion ;
20
+
21
+ private readonly bool onWindows ;
19
22
20
23
public PortableGitInstallDetails ( NPath targetInstallPath , bool onWindows )
21
24
{
25
+ this . onWindows = onWindows ;
22
26
var gitInstallPath = targetInstallPath . Combine ( ApplicationInfo . ApplicationName , PackageNameWithVersion ) ;
23
27
GitInstallPath = gitInstallPath ;
24
28
@@ -28,16 +32,23 @@ public PortableGitInstallDetails(NPath targetInstallPath, bool onWindows)
28
32
GitLfsExec += "git-lfs.exe" ;
29
33
30
34
GitExecPath = gitInstallPath . Combine ( "cmd" , GitExec ) ;
31
- GitLfsExecPath = gitInstallPath . Combine ( "mingw32" , "libexec" , "git-core" , GitLfsExec ) ;
32
35
}
33
36
else
34
37
{
35
38
GitExec = "git" ;
36
39
GitLfsExec = "git-lfs" ;
37
40
38
41
GitExecPath = gitInstallPath . Combine ( "bin" , GitExec ) ;
39
- GitLfsExecPath = gitInstallPath . Combine ( "libexec" , "git-core" , GitLfsExec ) ;
40
42
}
43
+
44
+ GitLfsExecPath = GetGitLfsExecPath ( gitInstallPath ) ;
45
+ }
46
+
47
+ public NPath GetGitLfsExecPath ( NPath gitInstallRoot )
48
+ {
49
+ return onWindows
50
+ ? gitInstallRoot . Combine ( "mingw32" , "libexec" , "git-core" , GitLfsExec )
51
+ : gitInstallRoot . Combine ( "libexec" , "git-core" , GitLfsExec ) ;
41
52
}
42
53
}
43
54
@@ -64,20 +75,74 @@ protected override NPath RunWithReturn(bool success)
64
75
return installDetails . GitExecPath ;
65
76
}
66
77
67
- var installGit = InstallGit ( ) ;
68
- if ( installGit )
78
+ Token . ThrowIfCancellationRequested ( ) ;
79
+
80
+ installDetails . GitInstallPath . DeleteIfExists ( ) ;
81
+ installDetails . GitInstallPath . EnsureParentDirectoryExists ( ) ;
82
+
83
+ Token . ThrowIfCancellationRequested ( ) ;
84
+
85
+ var extractTarget = NPath . CreateTempDirectory ( "git_install_task" ) ;
86
+ var installGit = InstallGit ( extractTarget ) ;
87
+ if ( ! installGit )
88
+ {
89
+ Logger . Warning ( "Failed PortableGitInstallTask" ) ;
90
+ return null ;
91
+ }
92
+
93
+ Token . ThrowIfCancellationRequested ( ) ;
94
+
95
+ var installGitLfs = InstallGitLfs ( extractTarget ) ;
96
+ if ( ! installGitLfs )
97
+ {
98
+ Logger . Warning ( "Failed PortableGitInstallTask" ) ;
99
+ return null ;
100
+ }
101
+
102
+ Token . ThrowIfCancellationRequested ( ) ;
103
+
104
+ var extractedMD5 = environment . FileSystem . CalculateFolderMD5 ( extractTarget ) ;
105
+ if ( ! extractedMD5 . Equals ( PortableGitInstallDetails . ExtractedMD5 , StringComparison . InvariantCultureIgnoreCase ) )
69
106
{
70
- var installGitLfs = InstallGitLfs ( ) ;
71
- if ( installGitLfs )
72
- {
73
- Logger . Trace ( "Completed PortableGitInstallTask" ) ;
74
- return installDetails . GitExecPath ;
75
- }
107
+ Logger . Warning ( "MD5 {0} does not match expected {1}" , extractedMD5 , PortableGitInstallDetails . ExtractedMD5 ) ;
108
+ Logger . Warning ( "Failed PortableGitInstallTask" ) ;
109
+ return null ;
76
110
}
77
111
78
- Logger . Warning ( "Unsuccessful PortableGitInstallTask" ) ;
112
+ var moveSuccessful = MoveExtractTarget ( extractTarget ) ;
113
+ if ( ! moveSuccessful )
114
+ {
115
+ Logger . Warning ( "Failed PortableGitInstallTask" ) ;
116
+ return null ;
117
+ }
79
118
80
- return null ;
119
+ Logger . Trace ( "Completed PortableGitInstallTask" ) ;
120
+ return installDetails . GitExecPath ;
121
+ }
122
+
123
+ private bool MoveExtractTarget ( NPath extractTarget )
124
+ {
125
+ try
126
+ {
127
+ Logger . Trace ( "Moving tempDirectory:\" {0}\" to extractTarget:\" {1}\" " , extractTarget ,
128
+ installDetails . GitInstallPath ) ;
129
+
130
+ extractTarget . Move ( installDetails . GitInstallPath ) ;
131
+
132
+ Logger . Trace ( "Deleting extractTarget:\" {0}\" " , extractTarget ) ;
133
+ extractTarget . DeleteIfExists ( ) ;
134
+
135
+ Logger . Trace ( "Completed PortableGitInstallTask" ) ;
136
+ }
137
+ catch ( Exception ex )
138
+ {
139
+ Logger . Warning ( ex , "Error Moving tempDirectory:\" {0}\" to extractTarget:\" {1}\" " , extractTarget ,
140
+ installDetails . GitInstallPath ) ;
141
+
142
+ return false ;
143
+ }
144
+
145
+ return true ;
81
146
}
82
147
83
148
private bool IsPortableGitExtracted ( )
@@ -88,22 +153,22 @@ private bool IsPortableGitExtracted()
88
153
return false ;
89
154
}
90
155
91
- var installMD5 = environment . FileSystem . CalculateFolderMD5 ( installDetails . GitInstallPath ) ;
92
- if ( ! installMD5 . Equals ( PortableGitInstallDetails . ExtractedMD5 , StringComparison . InvariantCultureIgnoreCase ) )
156
+ var fileListMD5 = environment . FileSystem . CalculateFolderMD5 ( installDetails . GitInstallPath , false ) ;
157
+ if ( ! fileListMD5 . Equals ( PortableGitInstallDetails . FileListMD5 , StringComparison . InvariantCultureIgnoreCase ) )
93
158
{
94
- Logger . Trace ( "MD5 {0} does not match expected {1}" , installMD5 , PortableGitInstallDetails . ExtractedMD5 ) ;
159
+ Logger . Trace ( "MD5 {0} does not match expected {1}" , fileListMD5 , PortableGitInstallDetails . FileListMD5 ) ;
95
160
return false ;
96
161
}
97
162
98
163
Logger . Trace ( "Git Present" ) ;
99
164
return true ;
100
165
}
101
166
102
- private bool InstallGit ( )
167
+ private bool InstallGit ( NPath targetPath )
103
168
{
104
169
Logger . Trace ( "InstallGit" ) ;
105
170
106
- var tempPath = NPath . GetTempFilename ( ) ;
171
+ var tempPath = NPath . CreateTempDirectory ( "git_zip_path" ) ;
107
172
var gitArchivePath = AssemblyResources . ToFile ( ResourceType . Platform , "git.zip" , tempPath , environment ) ;
108
173
109
174
if ( ! environment . FileSystem . FileExists ( gitArchivePath ) )
@@ -115,54 +180,31 @@ private bool InstallGit()
115
180
116
181
Token . ThrowIfCancellationRequested ( ) ;
117
182
118
- var tempDirectory = NPath . CreateTempDirectory ( "git_install_task" ) ;
119
-
120
183
try
121
184
{
122
- Logger . Trace ( "Extracting gitArchivePath:\" {0}\" tempDirectory :\" {1}\" " ,
123
- gitArchivePath , tempDirectory ) ;
185
+ Logger . Trace ( "Extracting gitArchivePath:\" {0}\" targetPath :\" {1}\" " ,
186
+ gitArchivePath , targetPath ) ;
124
187
125
- ZipHelper . ExtractZipFile ( gitArchivePath , tempDirectory , Token ) ;
188
+ ZipHelper . ExtractZipFile ( gitArchivePath , targetPath , Token ) ;
126
189
}
127
190
catch ( Exception ex )
128
191
{
129
192
Logger . Warning ( ex , "Error Extracting gitArchivePath:\" {0}\" tempDirectory:\" {1}\" " ,
130
- gitArchivePath , tempDirectory ) ;
193
+ gitArchivePath , targetPath ) ;
131
194
132
195
return false ;
133
196
}
134
197
135
- Token . ThrowIfCancellationRequested ( ) ;
136
-
137
- try
138
- {
139
- installDetails . GitInstallPath . DeleteIfExists ( ) ;
140
- installDetails . GitInstallPath . EnsureParentDirectoryExists ( ) ;
141
-
142
- Logger . Trace ( "Moving tempDirectory:\" {0}\" to gitInstallPath:\" {1}\" " ,
143
- tempDirectory , installDetails . GitInstallPath ) ;
144
-
145
- tempDirectory . Move ( installDetails . GitInstallPath ) ;
146
- }
147
- catch ( Exception ex )
148
- {
149
- Logger . Warning ( ex , "Error Moving tempDirectory:\" {0}\" to gitInstallPath:\" {1}\" " ,
150
- tempDirectory , installDetails . GitInstallPath ) ;
151
-
152
- return false ;
153
- }
154
-
155
- Logger . Trace ( "Deleting tempDirectory:\" {0}\" " , tempDirectory ) ;
156
- tempDirectory . DeleteIfExists ( ) ;
198
+ tempPath . DeleteIfExists ( ) ;
157
199
158
200
return true ;
159
201
}
160
202
161
- private bool InstallGitLfs ( )
203
+ private bool InstallGitLfs ( NPath targetPath )
162
204
{
163
205
Logger . Trace ( "InstallGitLfs" ) ;
164
206
165
- var tempPath = NPath . GetTempFilename ( ) ;
207
+ var tempPath = NPath . CreateTempDirectory ( "git_lfs_zip_path" ) ;
166
208
var gitLfsArchivePath = AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip" , tempPath , environment ) ;
167
209
168
210
if ( ! environment . FileSystem . FileExists ( gitLfsArchivePath ) )
@@ -173,7 +215,7 @@ private bool InstallGitLfs()
173
215
174
216
Token . ThrowIfCancellationRequested ( ) ;
175
217
176
- var tempDirectory = NPath . CreateTempDirectory ( "git_install_task " ) ;
218
+ var tempDirectory = NPath . CreateTempDirectory ( "git_lfs_extract_path " ) ;
177
219
178
220
try
179
221
{
@@ -182,22 +224,23 @@ private bool InstallGitLfs()
182
224
}
183
225
catch ( Exception ex )
184
226
{
185
- Logger . Warning ( $ "Error Extracting gitLfsArchivePath:\" { gitLfsArchivePath } \" tempDirectory:\" { tempDirectory } \" ", ex ) ;
227
+ Logger . Warning ( ex , $ "Error Extracting gitLfsArchivePath:\" { gitLfsArchivePath } \" tempDirectory:\" { tempDirectory } \" ") ;
186
228
return false ;
187
229
}
188
230
189
231
Token . ThrowIfCancellationRequested ( ) ;
190
232
191
233
var tempDirectoryGitLfsExec = tempDirectory . Combine ( installDetails . GitLfsExec ) ;
192
234
235
+ var targetLfsExecPath = installDetails . GetGitLfsExecPath ( targetPath ) ;
193
236
try
194
237
{
195
- Logger . Trace ( "Moving tempDirectoryGitLfsExec:\" {0}\" to gitLfsExecFullPath :\" {1}\" " , tempDirectoryGitLfsExec , installDetails . GitLfsExecPath ) ;
196
- tempDirectoryGitLfsExec . Move ( installDetails . GitLfsExecPath ) ;
238
+ Logger . Trace ( "Moving tempDirectoryGitLfsExec:\" {0}\" to targetLfsExecPath :\" {1}\" " , tempDirectoryGitLfsExec , targetLfsExecPath ) ;
239
+ tempDirectoryGitLfsExec . Move ( targetLfsExecPath ) ;
197
240
}
198
241
catch ( Exception ex )
199
242
{
200
- Logger . Warning ( $ "Error Moving tempDirectoryGitLfsExec:\" { tempDirectoryGitLfsExec } \" to gitLfsExecFullPath :\" { installDetails . GitLfsExecPath } \" ", ex ) ;
243
+ Logger . Warning ( ex , $ "Error Moving tempDirectoryGitLfsExec:\" { tempDirectoryGitLfsExec } \" to targetLfsExecPath :\" { targetLfsExecPath } \" ") ;
201
244
return false ;
202
245
}
203
246
0 commit comments