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
This commit is contained in:
Roberto Jimenez Sanchez
2025-12-02 22:36:30 +01:00
parent 0aaf6402f1
commit 42f18eb48d
@@ -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
}
}
}