mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 13:11:18 +00:00
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:
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user