fix find_or_create_folder: exact name match per component instead of endswith
This commit is contained in:
+19
-10
@@ -104,27 +104,36 @@ class AyonClient:
|
|||||||
def find_or_create_folder(
|
def find_or_create_folder(
|
||||||
self, project: str, path: str, folder_type: str = "Asset"
|
self, project: str, path: str, folder_type: str = "Asset"
|
||||||
) -> dict:
|
) -> 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)
|
f = self.find_folder(project, path)
|
||||||
if f:
|
if f:
|
||||||
return f
|
return f
|
||||||
|
|
||||||
parts = path.strip("/").split("/")
|
parts = path.strip("/").split("/")
|
||||||
current_parent = None
|
# Resolve root-level folders (no parentId)
|
||||||
|
|
||||||
# Find root parent
|
|
||||||
folders = self.list_folders(project)
|
folders = self.list_folders(project)
|
||||||
|
|
||||||
|
current_parent = None
|
||||||
for part in parts:
|
for part in parts:
|
||||||
found = None
|
found = None
|
||||||
for f in folders:
|
for f in folders:
|
||||||
fp = f.get("path", "").lstrip("/")
|
fp = f.get("path", "").lstrip("/")
|
||||||
pid = f.get("parentId") or ""
|
pid = f.get("parentId") or ""
|
||||||
if current_parent is None and not pid and fp == part:
|
|
||||||
found = f
|
if current_parent is None:
|
||||||
break
|
# Root level: name matches and no parent
|
||||||
if current_parent and f.get("parentId") == current_parent["id"] and fp.endswith(part):
|
if f.get("name") == part and not pid:
|
||||||
found = f
|
found = f
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
# Child level: name matches AND parentId matches
|
||||||
|
if f.get("name") == part and pid == current_parent["id"]:
|
||||||
|
found = f
|
||||||
|
break
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
current_parent = found
|
current_parent = found
|
||||||
|
|||||||
Reference in New Issue
Block a user