From 21af97db0995a37a7444fd28d4af54e4f4c550d5 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 10 Feb 2025 15:17:10 +0300 Subject: [PATCH] Provisioning: Fix local Write so it generates parent folders (#100349) --- pkg/registry/apis/provisioning/repository/local.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/registry/apis/provisioning/repository/local.go b/pkg/registry/apis/provisioning/repository/local.go index be144525863..a2bf188b237 100644 --- a/pkg/registry/apis/provisioning/repository/local.go +++ b/pkg/registry/apis/provisioning/repository/local.go @@ -350,21 +350,25 @@ func (r *localRepository) Update(ctx context.Context, path string, ref string, d return os.WriteFile(path, data, 0600) } -func (r *localRepository) Write(ctx context.Context, path, ref string, data []byte, comment string) error { +func (r *localRepository) Write(ctx context.Context, fpath, ref string, data []byte, comment string) error { if err := r.validateRequest(ref); err != nil { return err } - path, err := safepath.Join(r.path, path) + fpath, err := safepath.Join(r.path, fpath) if err != nil { return fmt.Errorf("join path: %w", err) } - if strings.HasSuffix(path, "/") { - return os.MkdirAll(path, 0600) + if strings.HasSuffix(fpath, "/") { + return os.MkdirAll(fpath, 0700) } - return os.WriteFile(path, data, 0600) + if err := os.MkdirAll(path.Dir(fpath), 0700); err != nil { + return apierrors.NewInternalError(fmt.Errorf("failed to create path: %w", err)) + } + + return os.WriteFile(fpath, data, 0600) } func (r *localRepository) Delete(ctx context.Context, path string, ref string, comment string) error {