From 3a42269da888ccef8e15834684730450d8ed7a66 Mon Sep 17 00:00:00 2001 From: xdadrm Date: Mon, 27 Jun 2022 20:19:21 +0200 Subject: [PATCH] Fixes WebDAV 0-bytes files Fixes the issue where files created via WebDAV show as 0-bytes size when read via fuse. --- weed/server/webdav_server.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go index 265dea03a..5140af2b4 100644 --- a/weed/server/webdav_server.go +++ b/weed/server/webdav_server.go @@ -48,6 +48,13 @@ type WebDavServer struct { Handler *webdav.Handler } +func max(x, y int64) int64 { + if x <= y { + return y + } + return x +} + func NewWebDavServer(option *WebDavOption) (ws *WebDavServer, err error) { fs, _ := NewWebDavFileSystem(option) @@ -496,6 +503,7 @@ func (f *WebDavFile) Write(buf []byte) (int, error) { written, err := f.bufWriter.Write(buf) if err == nil { + f.entry.Attributes.FileSize = uint64(max(f.off+int64(written), int64(f.entry.Attributes.FileSize))) glog.V(3).Infof("WebDavFileSystem.Write %v: written [%d,%d)", f.name, f.off, f.off+int64(len(buf))) f.off += int64(written) }