From 3e6ca6e7065a84f1a0a2a142358ac0c2fc0e9b48 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:39:52 +0500 Subject: [PATCH] [webdav] status code 500 if internal error from filer (#5865) --- weed/server/webdav_server.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go index f8d964552..dbe6dfed5 100644 --- a/weed/server/webdav_server.go +++ b/weed/server/webdav_server.go @@ -99,6 +99,7 @@ type FileInfo struct { modifiedTime time.Time etag string isDirectory bool + err error } func (fi *FileInfo) Name() string { return fi.name } @@ -109,6 +110,9 @@ func (fi *FileInfo) IsDir() bool { return fi.isDirectory } func (fi *FileInfo) Sys() interface{} { return nil } func (fi *FileInfo) ETag(ctx context.Context) (string, error) { + if fi.err != nil { + return "", fi.err + } return fi.etag, nil } @@ -269,7 +273,10 @@ func (fs *WebDavFileSystem) OpenFile(ctx context.Context, fullFilePath string, f fi, err := fs.stat(ctx, fullFilePath) if err != nil { - return nil, os.ErrNotExist + if err == os.ErrNotExist { + return nil, err + } + return &WebDavFile{fs: fs}, nil } if !strings.HasSuffix(fullFilePath, "/") && fi.IsDir() { fullFilePath += "/" @@ -365,12 +372,16 @@ func (fs *WebDavFileSystem) stat(ctx context.Context, fullFilePath string) (os.F var fi FileInfo entry, err := filer_pb.GetEntry(fs, fullpath) + if err != nil { + if err == filer_pb.ErrNotFound { + return nil, os.ErrNotExist + } + fi.err = err + return &fi, nil + } if entry == nil { return nil, os.ErrNotExist } - if err != nil { - return nil, err - } fi.size = int64(filer.FileSize(entry)) fi.name = string(fullpath) fi.mode = os.FileMode(entry.Attributes.FileMode) @@ -514,7 +525,9 @@ func (f *WebDavFile) Write(buf []byte) (int, error) { func (f *WebDavFile) Close() error { glog.V(2).Infof("WebDavFileSystem.Close %v", f.name) - + if f.bufWriter == nil { + return nil + } err := f.bufWriter.Close() if f.entry != nil {