Skip to content

Commit

Permalink
add fileid header when copying folders
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Feb 24, 2023
1 parent 83c7b4d commit c9b06bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fileid-on-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Send fileid on copy

When copying a folder oc-fileid header would not be added (unlinke when copying files)
this is fixed now.

https://github.com/cs3org/reva/pull/3685
39 changes: 33 additions & 6 deletions internal/http/services/owncloud/ocdav/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/rhttp"
"github.com/cs3org/reva/v2/pkg/rhttp/router"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -141,6 +142,8 @@ func (s *svc) handlePathCopy(w http.ResponseWriter, r *http.Request, ns string)
func (s *svc) executePathCopy(ctx context.Context, client gateway.GatewayAPIClient, w http.ResponseWriter, r *http.Request, cp *copy) error {
log := appctx.GetLogger(ctx)
log.Debug().Str("src", cp.sourceInfo.Path).Str("dst", cp.destination.Path).Msg("descending")

var fileid string
if cp.sourceInfo.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
// create dir
createReq := &provider.CreateContainerRequest{
Expand Down Expand Up @@ -196,6 +199,17 @@ func (s *svc) executePathCopy(ctx context.Context, client gateway.GatewayAPIClie
}
}

// we need to stat again to get the fileid
r, err := client.Stat(ctx, &provider.StatRequest{})
if err != nil {
return err
}

if r.GetStatus().GetCode() != rpc.Code_CODE_OK {
return fmt.Errorf("status code %d", r.GetStatus().GetCode())
}

fileid = storagespace.FormatResourceID(*r.GetInfo().GetId())
} else {
// copy file

Expand Down Expand Up @@ -294,10 +308,10 @@ func (s *svc) executePathCopy(ctx context.Context, client gateway.GatewayAPIClie
return err
}

if fileid := httpUploadRes.Header.Get(net.HeaderOCFileID); fileid != "" {
w.Header().Set(net.HeaderOCFileID, fileid)
}
fileid = httpUploadRes.Header.Get(net.HeaderOCFileID)
}

w.Header().Set(net.HeaderOCFileID, fileid)
return nil
}

Expand Down Expand Up @@ -353,6 +367,7 @@ func (s *svc) executeSpacesCopy(ctx context.Context, w http.ResponseWriter, clie
log := appctx.GetLogger(ctx)
log.Debug().Interface("src", cp.sourceInfo).Interface("dst", cp.destination).Msg("descending")

var fileid string
if cp.sourceInfo.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
// create dir
createReq := &provider.CreateContainerRequest{
Expand Down Expand Up @@ -401,6 +416,18 @@ func (s *svc) executeSpacesCopy(ctx context.Context, w http.ResponseWriter, clie
return err
}
}

// we need to stat again to get the fileid
r, err := client.Stat(ctx, &provider.StatRequest{Ref: cp.destination})
if err != nil {
return err
}

if r.GetStatus().GetCode() != rpc.Code_CODE_OK {
return fmt.Errorf("stat: status code %d", r.GetStatus().GetCode())
}

fileid = storagespace.FormatResourceID(*r.GetInfo().GetId())
} else {
// copy file
// 1. get download url
Expand Down Expand Up @@ -494,10 +521,10 @@ func (s *svc) executeSpacesCopy(ctx context.Context, w http.ResponseWriter, clie
return err
}

if fileid := httpUploadRes.Header.Get(net.HeaderOCFileID); fileid != "" {
w.Header().Set(net.HeaderOCFileID, fileid)
}
fileid = httpUploadRes.Header.Get(net.HeaderOCFileID)
}

w.Header().Set(net.HeaderOCFileID, fileid)
return nil
}

Expand Down

0 comments on commit c9b06bb

Please sign in to comment.