jobimpl-osbuild: split temp dir cleanup into its separate defer

It doesn't make sense to have them together.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2023-08-29 14:00:56 +02:00 committed by Ondřej Budai
parent f2f1c8d0f0
commit 19e45b528f

View file

@ -278,8 +278,6 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
}
osbuildJobResult.HostOS = hostOS
var outputDirectory string
// In all cases it is necessary to report result back to osbuild-composer worker API.
defer func() {
validateResult(osbuildJobResult, job.Id().String())
@ -288,18 +286,19 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
if err != nil {
logWithId.Errorf("Error reporting job result: %v", err)
}
}()
outputDirectory, err := os.MkdirTemp(impl.Output, job.Id().String()+"-*")
if err != nil {
return fmt.Errorf("error creating temporary output directory: %v", err)
}
defer func() {
err = os.RemoveAll(outputDirectory)
if err != nil {
logWithId.Errorf("Error removing temporary output directory (%s): %v", outputDirectory, err)
}
}()
outputDirectory, err = os.MkdirTemp(impl.Output, job.Id().String()+"-*")
if err != nil {
return fmt.Errorf("error creating temporary output directory: %v", err)
}
// Read the job specification
var jobArgs worker.OSBuildJob
err = job.Args(&jobArgs)