Skip to content

Commit

Permalink
fix upload of zero file sizes (cs3org#2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode authored and glpatcern committed Sep 23, 2021
1 parent 88ada40 commit 57fdecb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/fix-zero-file-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Fix uploads of empty files

This change fixes upload of empty files.
Previously this was broken and only worked for the
owncloud filesystem as it bypasses the semantics of the
InitiateFileUpload call to touch a local file.

https://github.com/cs3org/reva/pull/2055
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: "nextcloud"
linkTitle: "nextcloud"
weight: 10
description: >
Configuration for the nextcloud service
---

# _struct: config_

{{% dir name="endpoint" type="string" default="" %}}
The Nextcloud backend endpoint for user check [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/nextcloud/nextcloud.go#L48)
{{< highlight toml >}}
[auth.manager.nextcloud]
endpoint = ""
{{< /highlight >}}
{{% /dir %}}

54 changes: 26 additions & 28 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,39 +250,37 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
}
}

if length > 0 {
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
httpReq.Header.Set(datagateway.TokenTransportHeader, token)
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
httpReq.Header.Set(datagateway.TokenTransportHeader, token)

httpRes, err := s.client.Do(httpReq)
if err != nil {
log.Error().Err(err).Msg("error doing PUT request to data service")
w.WriteHeader(http.StatusInternalServerError)
httpRes, err := s.client.Do(httpReq)
if err != nil {
log.Error().Err(err).Msg("error doing PUT request to data service")
w.WriteHeader(http.StatusInternalServerError)
return
}
defer httpRes.Body.Close()
if httpRes.StatusCode != http.StatusOK {
if httpRes.StatusCode == http.StatusPartialContent {
w.WriteHeader(http.StatusPartialContent)
return
}
defer httpRes.Body.Close()
if httpRes.StatusCode != http.StatusOK {
if httpRes.StatusCode == http.StatusPartialContent {
w.WriteHeader(http.StatusPartialContent)
return
}
if httpRes.StatusCode == errtypes.StatusChecksumMismatch {
w.WriteHeader(http.StatusBadRequest)
b, err := Marshal(exception{
code: SabredavBadRequest,
message: "The computed checksum does not match the one received from the client.",
})
HandleWebdavError(&log, w, b, err)
return
}
log.Error().Err(err).Msg("PUT request to data server failed")
w.WriteHeader(httpRes.StatusCode)
if httpRes.StatusCode == errtypes.StatusChecksumMismatch {
w.WriteHeader(http.StatusBadRequest)
b, err := Marshal(exception{
code: SabredavBadRequest,
message: "The computed checksum does not match the one received from the client.",
})
HandleWebdavError(&log, w, b, err)
return
}
log.Error().Err(err).Msg("PUT request to data server failed")
w.WriteHeader(httpRes.StatusCode)
return
}

ok, err := chunking.IsChunked(ref.Path)
Expand Down

0 comments on commit 57fdecb

Please sign in to comment.