Skip to content

Commit

Permalink
Don't overwrite directories when uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Sep 8, 2020
1 parent 2c4cc89 commit 16f8162
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/reva/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var configureCommand = func() *command {
return err
}

c := &config{Host: text}
if err := writeConfig(c); err != nil {
conf = &config{Host: text}
if err := writeConfig(conf); err != nil {
return err
}
fmt.Println("config saved at ", getConfigFile())
Expand Down
17 changes: 17 additions & 0 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,23 @@ func (s *svc) initiateFileUpload(ctx context.Context, req *provider.InitiateFile
}, nil
}

statRes, err := c.Stat(ctx, &provider.StatRequest{
Ref: req.Ref,
})
if err != nil {
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating ref:"+req.Ref.String()),
}, nil
}

if statRes.Status.Code == rpc.Code_CODE_OK {
if statRes.Info != nil && statRes.Info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, errors.New("gateway: cannot overwrite directory: "+req.Ref.String()), "gateway: cannot overwrite directory"),
}, nil
}
}

storageRes, err := c.InitiateFileUpload(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling InitiateFileUpload")
Expand Down
7 changes: 6 additions & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate
}
if newRef.GetPath() == "/" {
return &provider.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, errors.New("can't upload to mount path"), ""),
Status: status.NewInternal(ctx, errors.New("can't upload to mount path"), "can't upload to mount path"),
}, nil
}
url := *s.dataServerURL
Expand Down Expand Up @@ -401,6 +401,11 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro
Status: status.NewInternal(ctx, err, "error unwrapping path"),
}, nil
}
if newRef.GetPath() == "/" {
return &provider.DeleteResponse{
Status: status.NewInternal(ctx, errors.New("can't delete mount path"), "can't delete mount path"),
}, nil
}

if err := s.storage.Delete(ctx, newRef); err != nil {
var st *rpc.Status
Expand Down

0 comments on commit 16f8162

Please sign in to comment.