fix: resolving path for shared item leaks parent info

when an item is shared, their path should stop at the closest directory
that is shared. eg if file c is in shared dir b which is in private dir
a, its public facing path should be b/c, not a/b/c. internally, the real
path is still a/b/c.
This commit is contained in:
2025-12-27 20:25:54 +00:00
parent bac21166fb
commit eca3b95c3e
2 changed files with 5 additions and 4 deletions

View File

@@ -33,9 +33,10 @@ const absolutePathWithPublicIDQuery = `WITH RECURSIVE path AS (
SELECT n.id, n.parent_id, n.name, n.public_id, p.depth + 1 SELECT n.id, n.parent_id, n.name, n.public_id, p.depth + 1
FROM vfs_nodes n FROM vfs_nodes n
JOIN path p ON n.id = p.parent_id JOIN path p ON n.id = p.parent_id
WHERE p.id != ?
) )
SELECT name, public_id FROM path SELECT name, public_id FROM path
WHERE EXISTS (SELECT 1 FROM path WHERE parent_id IS NULL) WHERE EXISTS (SELECT 1 FROM path WHERE id = ?)
ORDER BY depth DESC;` ORDER BY depth DESC;`
// Path represents a path to a node. // Path represents a path to a node.
@@ -67,9 +68,9 @@ func buildPathFromNodeID(ctx context.Context, db bun.IDB, nodeID uuid.UUID) (str
return JoinPath(path...), nil return JoinPath(path...), nil
} }
func buildNoteAbsolutePath(ctx context.Context, db bun.IDB, node *Node) (Path, error) { func buildNodeAbsolutePath(ctx context.Context, db bun.IDB, node *Node, rootID uuid.UUID) (Path, error) {
var segments []PathSegment var segments []PathSegment
err := db.NewRaw(absolutePathWithPublicIDQuery, node.ID).Scan(ctx, &segments) err := db.NewRaw(absolutePathWithPublicIDQuery, node.ID, rootID, rootID).Scan(ctx, &segments)
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, ErrNodeNotFound return nil, ErrNodeNotFound

View File

@@ -823,7 +823,7 @@ func (vfs *VirtualFS) RealPath(ctx context.Context, db bun.IDB, node *Node, scop
} else if !ok { } else if !ok {
return nil, ErrAccessDenied return nil, ErrAccessDenied
} }
return buildNoteAbsolutePath(ctx, db, node) return buildNodeAbsolutePath(ctx, db, node, scope.RootNodeID)
} }
func (vfs *VirtualFS) PermanentlyDeleteFiles(ctx context.Context, db bun.IDB, nodes []*Node, scope *Scope) error { func (vfs *VirtualFS) PermanentlyDeleteFiles(ctx context.Context, db bun.IDB, nodes []*Node, scope *Scope) error {