Fix: align POSIX hierarchy contract

This commit is contained in:
MangoPig
2026-06-22 11:13:06 +01:00
parent 07590f1c4f
commit 8a94d83e7e
5 changed files with 154 additions and 24 deletions
+46 -24
View File
@@ -321,18 +321,17 @@ func buildNode(rootPath, relPath string, entry fs.DirEntry, rootScope Scope) (No
func deriveScope(relPath string, rootScope Scope) Scope {
scope := rootScope
parts := strings.Split(relPath, "/")
if len(parts) >= 2 && parts[0] == "departments" && strings.HasPrefix(parts[1], "department-") {
scope.DepartmentSlug = strings.TrimPrefix(parts[1], "department-")
}
if len(parts) >= 4 && parts[0] == "departments" && parts[2] == "teams" && strings.HasPrefix(parts[3], "team-") {
scope.DepartmentSlug = strings.TrimPrefix(parts[1], "department-")
scope.TeamSlug = strings.TrimPrefix(parts[3], "team-")
}
if len(parts) >= 2 && parts[0] == "projects" && strings.HasPrefix(parts[1], "project-") {
scope.ProjectSlug = strings.TrimPrefix(parts[1], "project-")
}
if len(parts) >= 3 && parts[0] == "users" && parts[1] == "personals" && strings.HasPrefix(parts[2], "personal-") {
scope.PersonalSlug = strings.TrimPrefix(parts[2], "personal-")
for _, part := range parts {
switch {
case strings.HasPrefix(part, "department-"):
scope.DepartmentSlug = strings.TrimPrefix(part, "department-")
case strings.HasPrefix(part, "team-"):
scope.TeamSlug = strings.TrimPrefix(part, "team-")
case strings.HasPrefix(part, "project-"):
scope.ProjectSlug = strings.TrimPrefix(part, "project-")
case strings.HasPrefix(part, "personal-"):
scope.PersonalSlug = strings.TrimPrefix(part, "personal-")
}
}
return scope
}
@@ -344,6 +343,13 @@ func classifyPath(relPath string, isDir bool) (logicalType, fileRole string) {
fileRole = strings.TrimSuffix(name, filepath.Ext(name))
}
hasChildrenAncestor := pathContainsSegment(parts, "children")
hasTreeAncestor := pathContainsSegment(parts, "tree")
parentName := ""
if len(parts) >= 2 {
parentName = parts[len(parts)-2]
}
switch {
case relPath == "settings.json":
return "tenant", "settings"
@@ -392,26 +398,33 @@ func classifyPath(relPath string, isDir bool) (logicalType, fileRole string) {
return "department", fileRole
case len(parts) >= 2 && parts[0] == "projects" && strings.HasPrefix(parts[1], "project-"):
if isDir {
if len(parts) == 2 {
if strings.HasPrefix(name, "project-") {
return "project", ""
}
if len(parts) == 3 && parts[2] == "tree" {
if name == "children" {
return "project_children", ""
}
if name == "tree" {
return "project_tree", ""
}
if strings.Contains(relPath, "/tree/") || strings.HasSuffix(relPath, "/tree") {
if strings.HasPrefix(name, "folder-") {
return "folder", ""
}
if strings.HasPrefix(name, "item-") {
return "item", ""
}
if hasChildrenAncestor && strings.HasPrefix(name, "folder-") {
return "hierarchy_folder", ""
}
if hasTreeAncestor && strings.HasPrefix(name, "folder-") {
return "folder", ""
}
if hasTreeAncestor && strings.HasPrefix(name, "item-") {
return "item", ""
}
}
if strings.Contains(relPath, "/tree/") {
if strings.HasPrefix(parts[len(parts)-2], "item-") {
if hasChildrenAncestor && strings.HasPrefix(parentName, "folder-") {
return "hierarchy_folder", fileRole
}
if hasTreeAncestor {
if strings.HasPrefix(parentName, "item-") {
return "item", fileRole
}
if strings.HasPrefix(parts[len(parts)-2], "folder-") {
if strings.HasPrefix(parentName, "folder-") {
return "folder", fileRole
}
}
@@ -456,6 +469,15 @@ func classifyPath(relPath string, isDir bool) (logicalType, fileRole string) {
}
}
func pathContainsSegment(parts []string, target string) bool {
for _, part := range parts {
if part == target {
return true
}
}
return false
}
func projectionParentPath(relPath string) *string {
if relPath == "" || relPath == rootProjectionPath {
return nil