@@ -201,48 +201,42 @@ func (executor *Executor) PopulateCloneAndWorkingDirEnvironmentVariables(environ
201
201
result [key ] = value
202
202
}
203
203
204
- _ , hasCloneDir := result ["CIRRUS_CLONE_DIR" ]
205
- _ , hasWorkingDir := result ["CIRRUS_WORKING_DIR" ]
206
-
207
- if hasCloneDir && ! hasWorkingDir {
208
- // Only clone was overridden. Make sure $CIRRUS_WORKING_DIR is set
209
- result ["CIRRUS_WORKING_DIR" ] = "$CIRRUS_CLONE_DIR"
210
- }
211
- if ! hasCloneDir && hasWorkingDir {
212
- // User did override working dir
213
- if ! strings .Contains (result ["CIRRUS_WORKING_DIR" ], "CIRRUS_CLONE_DIR" ) {
214
- // If working dir doesn't depend on clone dir then we can default clone dir to the one provided by user
215
- result ["CIRRUS_CLONE_DIR" ] = "$CIRRUS_WORKING_DIR"
216
- hasCloneDir = true
204
+ if _ , ok := result ["CIRRUS_WORKING_DIR" ]; ! ok {
205
+ if executor .preCreatedWorkingDir != "" {
206
+ result ["CIRRUS_WORKING_DIR" ] = executor .preCreatedWorkingDir
207
+ } else {
208
+ result ["CIRRUS_WORKING_DIR" ] = makeScratchDir (executor )
217
209
}
218
210
}
219
211
220
- if ! hasCloneDir && ! hasWorkingDir {
221
- // none of the dirs are explicitly set. Make sure they'll be the same
222
- result ["CIRRUS_WORKING_DIR" ] = "$CIRRUS_CLONE_DIR"
223
- }
224
-
225
- if ! hasCloneDir && executor .preCreatedWorkingDir != "" {
226
- // none of the dirs are explicitly set. Make sure they'll be the same
227
- result ["CIRRUS_CLONE_DIR" ] = executor .preCreatedWorkingDir
228
- }
229
-
230
212
if _ , ok := result ["CIRRUS_CLONE_DIR" ]; ! ok {
231
- defaultTempDirPath := filepath . Join ( os . TempDir (), "cirrus-ci-build" )
232
- if _ , err := os . Stat ( defaultTempDirPath ); os . IsNotExist ( err ) {
233
- result ["CIRRUS_CLONE_DIR" ] = filepath . ToSlash ( defaultTempDirPath )
234
- } else if executor . commandFrom != "" {
235
- // Default folder exists and we continue execution. Therefore we need to use it.
236
- result ["CIRRUS_CLONE_DIR" ] = filepath . ToSlash ( defaultTempDirPath )
213
+ // Get the working directory here again after we've
214
+ // dealt with it's potential absence above
215
+ workingDir := result ["CIRRUS_WORKING_DIR" ]
216
+
217
+ if strings . Contains ( workingDir , "CIRRUS_CLONE_DIR" ) {
218
+ result ["CIRRUS_CLONE_DIR" ] = makeScratchDir ( executor )
237
219
} else {
238
- uniqueTempDirPath , _ := ioutil .TempDir (os .TempDir (), fmt .Sprintf ("cirrus-task-%d" , executor .taskIdentification .TaskId ))
239
- result ["CIRRUS_CLONE_DIR" ] = filepath .ToSlash (uniqueTempDirPath )
220
+ result ["CIRRUS_CLONE_DIR" ] = workingDir
240
221
}
241
222
}
242
223
243
224
return result
244
225
}
245
226
227
+ func makeScratchDir (executor * Executor ) string {
228
+ defaultTempDirPath := filepath .Join (os .TempDir (), "cirrus-ci-build" )
229
+ if _ , err := os .Stat (defaultTempDirPath ); os .IsNotExist (err ) {
230
+ return filepath .ToSlash (defaultTempDirPath )
231
+ } else if executor .commandFrom != "" {
232
+ // Default folder exists and we continue execution. Therefore we need to use it.
233
+ return filepath .ToSlash (defaultTempDirPath )
234
+ } else {
235
+ uniqueTempDirPath , _ := ioutil .TempDir (os .TempDir (), fmt .Sprintf ("cirrus-task-%d" , executor .taskIdentification .TaskId ))
236
+ return filepath .ToSlash (uniqueTempDirPath )
237
+ }
238
+ }
239
+
246
240
func (executor * Executor ) performStep (env map [string ]string , currentStep * api.Command ) error {
247
241
success := false
248
242
signaledToExit := false
0 commit comments