From bab5cd4b41a8e0949d608c3c873dd6dc675ba41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Mon, 13 Oct 2025 20:38:49 +0200 Subject: [PATCH] Clean up temp dir --- client/internal/updatemanager/manager.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/internal/updatemanager/manager.go b/client/internal/updatemanager/manager.go index 13b0ffb56..2b4562430 100644 --- a/client/internal/updatemanager/manager.go +++ b/client/internal/updatemanager/manager.go @@ -318,6 +318,17 @@ func downloadFileToTemporaryDir(ctx context.Context, fileURL string) (string, er if err != nil { return "", fmt.Errorf("error creating temporary directory: %w", err) } + + // Clean up temp directory on error + var success bool + defer func() { + if !success { + if err := os.RemoveAll(tempDir); err != nil { + log.Errorf("error cleaning up temporary directory: %v", err) + } + } + }() + fileNameParts := strings.Split(fileURL, "/") out, err := os.Create(filepath.Join(tempDir, fileNameParts[len(fileNameParts)-1])) if err != nil { @@ -355,6 +366,7 @@ func downloadFileToTemporaryDir(ctx context.Context, fileURL string) (string, er log.Debugf("downloaded update file to %s", out.Name()) + success = true // Mark success to prevent cleanup return out.Name(), nil }