Skip to content

Commit

Permalink
Return wrapped paths for recycled items in storage provider (#2368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Feb 7, 2022
1 parent 5261583 commit 882add6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/wrap-recycle-paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Return wrapped paths for recycled items in storage provider

https://github.com/cs3org/reva/pull/2368
21 changes: 21 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,15 @@ func (s *service) ListRecycle(ctx context.Context, req *provider.ListRecycleRequ
}, nil
}

prefixMountpoint := utils.IsAbsoluteReference(req.Ref)
for _, md := range items {
if err := s.wrapReference(ctx, md.Ref, prefixMountpoint); err != nil {
return &provider.ListRecycleResponse{
Status: status.NewInternal(ctx, err, "error wrapping path"),
}, nil
}
}

res := &provider.ListRecycleResponse{
Status: status.NewOK(ctx),
RecycleItems: items,
Expand Down Expand Up @@ -1538,6 +1547,18 @@ func (s *service) wrap(ctx context.Context, ri *provider.ResourceInfo, prefixMou
return nil
}

func (s *service) wrapReference(ctx context.Context, ref *provider.Reference, prefixMountpoint bool) error {
if ref.ResourceId != nil && ref.ResourceId.StorageId == "" {
// For wrapper drivers, the storage ID might already be set. In that case, skip setting it
ref.ResourceId.StorageId = s.mountID
}
if prefixMountpoint {
// TODO move mount path prefixing to the gateway
ref.Path = path.Join(s.mountPath, ref.Path)
}
return nil
}

type descendingMtime []*provider.FileVersion

func (v descendingMtime) Len() int {
Expand Down
15 changes: 8 additions & 7 deletions internal/http/services/owncloud/ocdav/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s
}

if depth == "0" {
propRes, err := h.formatTrashPropfind(ctx, s, u, nil, nil)
propRes, err := h.formatTrashPropfind(ctx, s, u, nil, nil, basePath)
if err != nil {
sublog.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -270,7 +270,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s
}
}

propRes, err := h.formatTrashPropfind(ctx, s, u, &pf, items)
propRes, err := h.formatTrashPropfind(ctx, s, u, &pf, items, basePath)
if err != nil {
sublog.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -286,7 +286,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s
}
}

func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *userpb.User, pf *propfindXML, items []*provider.RecycleItem) (string, error) {
func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *userpb.User, pf *propfindXML, items []*provider.RecycleItem, basePath string) (string, error) {
responses := make([]*responseXML, 0, len(items)+1)
// add trashbin dir . entry
responses = append(responses, &responseXML{
Expand All @@ -311,7 +311,7 @@ func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *us
})

for i := range items {
res, err := h.itemToPropResponse(ctx, s, u, pf, items[i])
res, err := h.itemToPropResponse(ctx, s, u, pf, items[i], basePath)
if err != nil {
return "", err
}
Expand All @@ -331,7 +331,7 @@ func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *us
// itemToPropResponse needs to create a listing that contains a key and destination
// the key is the name of an entry in the trash listing
// for now we need to limit trash to the users home, so we can expect all trash keys to have the home storage as the opaque id
func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *userpb.User, pf *propfindXML, item *provider.RecycleItem) (*responseXML, error) {
func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *userpb.User, pf *propfindXML, item *provider.RecycleItem, basePath string) (*responseXML, error) {

baseURI := ctx.Value(ctxKeyBaseURI).(string)
ref := path.Join(baseURI, u.Username, item.Key)
Expand All @@ -348,6 +348,7 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use

t := utils.TSToTime(item.DeletionTime).UTC()
dTime := t.Format(time.RFC1123Z)
restorePath := strings.TrimPrefix(strings.TrimPrefix(item.Ref.Path, basePath), "/")

// when allprops has been requested
if pf.Allprop != nil {
Expand All @@ -358,7 +359,7 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use
})
// yes this is redundant, can be derived from oc:trashbin-original-location which contains the full path, clients should not fetch it
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-filename", path.Base(item.Ref.Path)))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Ref.Path, "/")))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-location", restorePath))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-delete-timestamp", strconv.FormatUint(item.DeletionTime.Seconds, 10)))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-delete-datetime", dTime))
if item.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
Expand Down Expand Up @@ -397,7 +398,7 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-filename", path.Base(item.Ref.Path)))
case "trashbin-original-location":
// TODO (jfd) double check and clarify the cs3 spec what the Key is about and if Path is only the folder that contains the file or if it includes the filename
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Ref.Path, "/")))
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-location", restorePath))
case "trashbin-delete-datetime":
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-delete-datetime", dTime))
case "trashbin-delete-timestamp":
Expand Down

0 comments on commit 882add6

Please sign in to comment.