From 6431df692fa0305e8b8039fb1e885c01e4ecf311 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Fri, 27 Nov 2026 11:53:09 +0100 Subject: [PATCH] fix(graph): give a share root among the search hits no parent path The share root is the root of the mountpoint drive. Described as a child of / there, driveId, path and name led to a folder of the same name inside the share. --- .../pkg/service/v0/searchquery_mapping.go | 13 ++++++++++--- .../graph/pkg/service/v0/searchquery_test.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/services/graph/pkg/service/v0/searchquery_mapping.go b/services/graph/pkg/service/v0/searchquery_mapping.go index cc9ee6689c..6fa833a672 100644 --- a/services/graph/pkg/service/v0/searchquery_mapping.go +++ b/services/graph/pkg/service/v0/searchquery_mapping.go @@ -202,12 +202,19 @@ func searchEntityToDriveItem(e *searchmsg.Entity, uid string) *libregraph.DriveI if p := e.GetParentId(); p != nil { ref := libregraph.NewItemReference() ref.SetDriveId(storagespace.FormatStorageID(p.GetStorageId(), p.GetSpaceId())) + refPath := e.GetRef().GetPath() // the path of a hit in a share is relative to the mountpoint, so that is the drive - if mountpoint := e.GetRef().GetResourceId(); mountpoint != nil && e.GetRemoteItemId() != nil { + mountpoint := e.GetRef().GetResourceId() + inShare := mountpoint != nil && e.GetRemoteItemId() != nil + if inShare { ref.SetDriveId(searchResourceID(mountpoint)) } - ref.SetId(searchResourceID(p)) - if refPath := e.GetRef().GetPath(); refPath != "" { + // the share root is the root of that drive and has no parent in it + isShareRoot := inShare && path.Join("/", refPath) == "/" + if !isShareRoot { + ref.SetId(searchResourceID(p)) + } + if refPath != "" && !isShareRoot { // the index keeps paths relative to the space root (./dir/file) parent := path.Dir(path.Join("/", refPath)) ref.SetPath(parent) diff --git a/services/graph/pkg/service/v0/searchquery_test.go b/services/graph/pkg/service/v0/searchquery_test.go index b80bd3784c..fb70af60f3 100644 --- a/services/graph/pkg/service/v0/searchquery_test.go +++ b/services/graph/pkg/service/v0/searchquery_test.go @@ -254,6 +254,24 @@ var _ = ginkgo.Describe("SearchQuery", func() { Expect(parent.Path).To(Equal("/2026")) }) + ginkgo.It("gives the share root itself no parent in the drive of the mountpoint", func() { + g, _ := graphWithSearchAnswer(oneMatch(&searchmsg.Entity{ + Id: &searchmsg.ResourceID{StorageId: "1", SpaceId: "2", OpaqueId: "5"}, + ParentId: &searchmsg.ResourceID{StorageId: "1", SpaceId: "2", OpaqueId: "4"}, + Ref: &searchmsg.Reference{ResourceId: &searchmsg.ResourceID{StorageId: "jail", SpaceId: "jail", OpaqueId: "share"}, Path: "."}, + RemoteItemId: &searchmsg.ResourceID{StorageId: "1", SpaceId: "2", OpaqueId: "5"}, + Name: "Project X", + })) + rr := postSearchQuery(g, searchQueryBody(`"from": 0`)) + Expect(rr.Code).To(Equal(http.StatusOK), rr.Body.String()) + + parent := hitsContainer(rr).Hits[0].Resource.ParentReference + Expect(parent.DriveId).To(Equal("jail$jail!share")) + Expect(parent.Id).To(BeEmpty()) + Expect(parent.Path).To(BeEmpty()) + Expect(parent.Name).To(BeNil()) + }) + ginkgo.DescribeTable("validatePagination enforces the spec's from/size bounds", func(from, size *int32, wantErr bool) { err := validatePagination(from, size)