From 42f18eb48df243462be2a8014dfb281027cba39b Mon Sep 17 00:00:00 2001 From: Roberto Jimenez Sanchez Date: Tue, 2 Dec 2025 22:36:30 +0100 Subject: [PATCH] fix: use options.Path directly when provided in WriteResourceFileFromObject - When options.Path is provided, use it directly without resolving folder paths - This ensures export paths with folder structure are preserved correctly - Fixes folder structure export test --- .../apis/provisioning/resources/resources.go | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/pkg/registry/apis/provisioning/resources/resources.go b/pkg/registry/apis/provisioning/resources/resources.go index dff8ef4011c..e8f002fb545 100644 --- a/pkg/registry/apis/provisioning/resources/resources.go +++ b/pkg/registry/apis/provisioning/resources/resources.go @@ -169,35 +169,33 @@ func (r *ResourcesManager) WriteResourceFileFromObject(ctx context.Context, obj fileName := slugify.Slugify(title) + ".json" - // Use folder structure: get the folder path from the resource and append it to Path - folder := meta.GetFolder() - // Get the absolute path of the folder - rootFolder := RootFolder(r.repo.Config()) - - // If no folder is specified in the file, set it to the root to ensure everything is written under it - var fid Folder - if folder == "" { - fid = Folder{ID: rootFolder} - meta.SetFolder(rootFolder) // Set the folder in the metadata to the root folder - } else { - var ok bool - fid, ok = r.folders.Tree().DirPath(folder, rootFolder) - if !ok { - // Fallback: try without rootFolder (for instance targets where rootFolder is empty) - fid, ok = r.folders.Tree().DirPath(folder, "") - if !ok { - return "", fmt.Errorf("folder %s NOT found in tree", folder) - } - } - } - // Build the full path: start with options.Path, then add folder path, then filename basePath := options.Path - if fid.Path != "" { - if basePath != "" { - basePath = safepath.Join(basePath, fid.Path) + + // If options.Path is provided, use it directly (it already includes folder structure from export). + // Otherwise, resolve folder path from the repository tree. + if basePath == "" { + folder := meta.GetFolder() + // Get the absolute path of the folder + rootFolder := RootFolder(r.repo.Config()) + + if folder == "" { + // If no folder is specified and no path is provided, set it to the root to ensure everything is written under it + meta.SetFolder(rootFolder) // Set the folder in the metadata to the root folder } else { - basePath = fid.Path + var ok bool + var fid Folder + fid, ok = r.folders.Tree().DirPath(folder, rootFolder) + if !ok { + // Fallback: try without rootFolder (for instance targets where rootFolder is empty) + fid, ok = r.folders.Tree().DirPath(folder, "") + if !ok { + return "", fmt.Errorf("folder %s NOT found in tree", folder) + } + } + if fid.Path != "" { + basePath = fid.Path + } } }