fix find_or_create_folder: exact name match per component instead of endswith
This commit is contained in:
+15
-6
@@ -104,25 +104,34 @@ class AyonClient:
|
||||
def find_or_create_folder(
|
||||
self, project: str, path: str, folder_type: str = "Asset"
|
||||
) -> dict:
|
||||
"""Find existing folder or create it (including parents)."""
|
||||
"""Find existing folder or create it (including parents).
|
||||
|
||||
Walks the path component by component — each component must match
|
||||
the exact folder name under the current parent, not just endswith.
|
||||
"""
|
||||
f = self.find_folder(project, path)
|
||||
if f:
|
||||
return f
|
||||
|
||||
parts = path.strip("/").split("/")
|
||||
current_parent = None
|
||||
|
||||
# Find root parent
|
||||
# Resolve root-level folders (no parentId)
|
||||
folders = self.list_folders(project)
|
||||
|
||||
current_parent = None
|
||||
for part in parts:
|
||||
found = None
|
||||
for f in folders:
|
||||
fp = f.get("path", "").lstrip("/")
|
||||
pid = f.get("parentId") or ""
|
||||
if current_parent is None and not pid and fp == part:
|
||||
|
||||
if current_parent is None:
|
||||
# Root level: name matches and no parent
|
||||
if f.get("name") == part and not pid:
|
||||
found = f
|
||||
break
|
||||
if current_parent and f.get("parentId") == current_parent["id"] and fp.endswith(part):
|
||||
else:
|
||||
# Child level: name matches AND parentId matches
|
||||
if f.get("name") == part and pid == current_parent["id"]:
|
||||
found = f
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user