You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/03/19 15:18:58 UTC

[camel-k] 12/13: fix: Correctly defer temporary build directory clean-up

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit c6073e0e76042f1e28baf746a9643eb1baacc500
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Mar 19 11:29:01 2021 +0100

    fix: Correctly defer temporary build directory clean-up
---
 pkg/controller/build/schedule_routine.go | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/pkg/controller/build/schedule_routine.go b/pkg/controller/build/schedule_routine.go
index 1f31852..10ad9a7 100644
--- a/pkg/controller/build/schedule_routine.go
+++ b/pkg/controller/build/schedule_routine.go
@@ -19,6 +19,7 @@ package build
 
 import (
 	"context"
+	"fmt"
 	"io/ioutil"
 	"os"
 	"path"
@@ -118,7 +119,6 @@ func (action *scheduleRoutineAction) runBuild(ctx context.Context, build *v1.Bui
 	}
 
 	buildDir := ""
-	defer os.RemoveAll(buildDir)
 
 	for i, task := range build.Spec.Tasks {
 		// Coordinate the build and context directories across the sequence of tasks
@@ -130,11 +130,21 @@ func (action *scheduleRoutineAction) runBuild(ctx context.Context, build *v1.Bui
 					break
 				}
 				t.BuildDir = tmpDir
+				// Deferring in the for loop is what we want here
+				defer os.RemoveAll(tmpDir)
 			}
 			buildDir = t.BuildDir
 		} else if t := task.Spectrum; t != nil && t.ContextDir == "" {
+			if buildDir == "" {
+				status.Failed(fmt.Errorf("cannot determine context directory for task %s", t.Name))
+				break
+			}
 			t.ContextDir = path.Join(buildDir, builder.ContextDir)
 		} else if t := task.S2i; t != nil && t.ContextDir == "" {
+			if buildDir == "" {
+				status.Failed(fmt.Errorf("cannot determine context directory for task %s", t.Name))
+				break
+			}
 			t.ContextDir = path.Join(buildDir, builder.ContextDir)
 		}