From b832ddd1ef949a99f60f4bf1fd321b70ee592626 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 3 Jan 2024 21:50:32 +0500 Subject: [PATCH] fix: return etag with md5 in webdav responses (#5158) --- weed/server/webdav_server.go | 6 ++++++ weed/server/wrapped_webdav_fs.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go index 35c554839..217caa59b 100644 --- a/weed/server/webdav_server.go +++ b/weed/server/webdav_server.go @@ -96,6 +96,7 @@ type FileInfo struct { size int64 mode os.FileMode modifiedTime time.Time + etag string isDirectory bool } @@ -106,6 +107,10 @@ func (fi *FileInfo) ModTime() time.Time { return fi.modifiedTime } func (fi *FileInfo) IsDir() bool { return fi.isDirectory } func (fi *FileInfo) Sys() interface{} { return nil } +func (fi *FileInfo) ETag(ctx context.Context) (string, error) { + return fi.etag, nil +} + type WebDavFile struct { fs *WebDavFileSystem name string @@ -369,6 +374,7 @@ func (fs *WebDavFileSystem) stat(ctx context.Context, fullFilePath string) (os.F fi.name = string(fullpath) fi.mode = os.FileMode(entry.Attributes.FileMode) fi.modifiedTime = time.Unix(entry.Attributes.Mtime, 0) + fi.etag = filer.ETag(entry) fi.isDirectory = entry.IsDirectory if fi.name == "/" { diff --git a/weed/server/wrapped_webdav_fs.go b/weed/server/wrapped_webdav_fs.go index 93e2b3122..f110d41a4 100644 --- a/weed/server/wrapped_webdav_fs.go +++ b/weed/server/wrapped_webdav_fs.go @@ -95,3 +95,11 @@ func (w wrappedFileInfo) Name() string { name := w.FileInfo.Name() return strings.TrimPrefix(name, *w.subFolder) } + +func (w wrappedFileInfo) ETag(ctx context.Context) (string, error) { + etag, _ := w.FileInfo.(webdav.ETager).ETag(ctx) + if len(etag) == 0 { + return etag, webdav.ErrNotImplemented + } + return etag, nil +}