From c951fd3dc72a8d3c8a0d2c329e96c99a961e33e3 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Date: Fri, 3 Apr 2026 15:44:07 +0000 Subject: [PATCH 1/2] fix: handle app download dir stat errors --- pkg/splunk/enterprise/util.go | 3 +++ pkg/splunk/enterprise/util_test.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/splunk/enterprise/util.go b/pkg/splunk/enterprise/util.go index fd7900787..14209bbd8 100644 --- a/pkg/splunk/enterprise/util.go +++ b/pkg/splunk/enterprise/util.go @@ -553,6 +553,9 @@ func createAppDownloadDir(ctx context.Context, path string) error { scopedLog.Error(errDir, "Unable to create directory at path") return errDir } + } else if err != nil { + scopedLog.Error(err, "Unable to access path") + return err } return nil } diff --git a/pkg/splunk/enterprise/util_test.go b/pkg/splunk/enterprise/util_test.go index 7168e366a..9e1ce9d16 100644 --- a/pkg/splunk/enterprise/util_test.go +++ b/pkg/splunk/enterprise/util_test.go @@ -22,6 +22,7 @@ import ( //"io" "os" + "path/filepath" "strconv" "strings" "testing" @@ -1196,7 +1197,13 @@ func TestCreateAppDownloadDir(t *testing.T) { t.Errorf("Didn't expect error") } - err = createAppDownloadDir(ctx, "/xyzzz.txt") + blockerFile, err := os.CreateTemp(t.TempDir(), "app-download-dir-blocker") + if err != nil { + t.Fatalf("failed to create blocker file: %v", err) + } + defer blockerFile.Close() + + err = createAppDownloadDir(ctx, filepath.Join(blockerFile.Name(), "child")) if err == nil { t.Errorf("Expected error") } From c8259be15c0ca11ae247e4e6a16717cd167eff97 Mon Sep 17 00:00:00 2001 From: vivekr-splunk Date: Wed, 8 Apr 2026 14:11:07 +0000 Subject: [PATCH 2/2] cleanup createAppDownloadDir review feedback --- pkg/splunk/enterprise/util.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pkg/splunk/enterprise/util.go b/pkg/splunk/enterprise/util.go index 14209bbd8..3c16f0d81 100644 --- a/pkg/splunk/enterprise/util.go +++ b/pkg/splunk/enterprise/util.go @@ -543,21 +543,12 @@ func getBundlePushState(afwPipeline *AppInstallPipeline) enterpriseApi.BundlePus } // createAppDownloadDir creates the app download directory on the operator pod -func createAppDownloadDir(ctx context.Context, path string) error { - reqLogger := log.FromContext(ctx) - scopedLog := reqLogger.WithName("createAppDownloadDir").WithValues("path", path) +func createAppDownloadDir(_ context.Context, path string) error { _, err := os.Stat(path) if errors.Is(err, os.ErrNotExist) { - errDir := os.MkdirAll(path, 0700) - if errDir != nil { - scopedLog.Error(errDir, "Unable to create directory at path") - return errDir - } - } else if err != nil { - scopedLog.Error(err, "Unable to access path") - return err + return os.MkdirAll(path, 0700) } - return nil + return err } // getAvailableDiskSpace returns the disk space available to download apps at volume "/opt/splunk/appframework"