From e1f68d0e8887947c21877e967e783c598ab5aba7 Mon Sep 17 00:00:00 2001 From: Roman Perekhod <2403905@gmail.com> Date: Mon, 18 Sep 2023 13:27:38 +0200 Subject: [PATCH] Fix the error when the user trying to overwrite a file with an empty file (#4193) Co-authored-by: Roman Perekhod --- changelog/unreleased/fix-overwrite-file.md | 5 +++ internal/http/services/owncloud/ocdav/put.go | 47 +++++++++++--------- 2 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 changelog/unreleased/fix-overwrite-file.md diff --git a/changelog/unreleased/fix-overwrite-file.md b/changelog/unreleased/fix-overwrite-file.md new file mode 100644 index 0000000000..dc41dacbdd --- /dev/null +++ b/changelog/unreleased/fix-overwrite-file.md @@ -0,0 +1,5 @@ +Bugfix: fix overwrite a file with an empty file + +Fix the error when the user trying to overwrite a file with an empty file + +https://github.com/cs3org/reva/pull/4193 diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 58063e5ee2..7c30eb1275 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -172,32 +172,35 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ w.WriteHeader(http.StatusInternalServerError) return } - if tfRes.Status.Code != rpc.Code_CODE_OK { - log.Error().Interface("status", tfRes.Status).Msg("error touching file") - w.WriteHeader(http.StatusInternalServerError) - return - } - sRes, err := client.Stat(ctx, &provider.StatRequest{ - Ref: ref, - }) - if err != nil { - log.Error().Err(err).Msg("error sending grpc touch file request") - w.WriteHeader(http.StatusInternalServerError) + if tfRes.Status.Code == rpc.Code_CODE_OK { + sRes, err := client.Stat(ctx, &provider.StatRequest{ + Ref: ref, + }) + if err != nil { + log.Error().Err(err).Msg("error sending grpc touch file request") + w.WriteHeader(http.StatusInternalServerError) + return + } + if sRes.Status.Code != rpc.Code_CODE_OK { + log.Error().Interface("status", sRes.Status).Msg("error touching file") + errors.HandleErrorStatus(&log, w, sRes.Status) + return + } + + w.Header().Set(net.HeaderETag, sRes.Info.Etag) + w.Header().Set(net.HeaderOCETag, sRes.Info.Etag) + w.Header().Set(net.HeaderOCFileID, storagespace.FormatResourceID(*sRes.Info.Id)) + w.Header().Set(net.HeaderLastModified, net.RFC1123Z(sRes.Info.Mtime)) + + w.WriteHeader(http.StatusCreated) return } - if sRes.Status.Code != rpc.Code_CODE_OK { - log.Error().Interface("status", sRes.Status).Msg("error touching file") - w.WriteHeader(http.StatusInternalServerError) + + if tfRes.Status.Code != rpc.Code_CODE_ALREADY_EXISTS { + log.Error().Interface("status", tfRes.Status).Msg("error touching file") + errors.HandleErrorStatus(&log, w, tfRes.Status) return } - - w.Header().Set(net.HeaderETag, sRes.Info.Etag) - w.Header().Set(net.HeaderOCETag, sRes.Info.Etag) - w.Header().Set(net.HeaderOCFileID, storagespace.FormatResourceID(*sRes.Info.Id)) - w.Header().Set(net.HeaderLastModified, net.RFC1123Z(sRes.Info.Mtime)) - - w.WriteHeader(http.StatusCreated) - return } utils.AppendPlainToOpaque(opaque, net.HeaderUploadLength, strconv.FormatInt(length, 10))