Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileID Header on COPY #3685

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{Ref: cp.destination})
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