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 <[email protected]>
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)
                }
 

Reply via email to