From f0f981e7c8bd74f3df277539407bcb6b6a483050 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 3 May 2019 14:12:51 -0700 Subject: [PATCH] webdav: fix directory renaming --- weed/filer2/filer_client_util.go | 2 +- weed/server/filer_grpc_server_rename.go | 2 ++ weed/server/webdav_server.go | 22 ++++++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/weed/filer2/filer_client_util.go b/weed/filer2/filer_client_util.go index 0986a54cd..7e093eea2 100644 --- a/weed/filer2/filer_client_util.go +++ b/weed/filer2/filer_client_util.go @@ -106,7 +106,7 @@ func GetEntry(ctx context.Context, filerClient FilerClient, fullFilePath string) resp, err := client.LookupDirectoryEntry(ctx, request) if err != nil { if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) { - return ErrNotFound + return nil } glog.V(3).Infof("read %s attr %v: %v", fullFilePath, request, err) return err diff --git a/weed/server/filer_grpc_server_rename.go b/weed/server/filer_grpc_server_rename.go index bd9f8c0be..568b10428 100644 --- a/weed/server/filer_grpc_server_rename.go +++ b/weed/server/filer_grpc_server_rename.go @@ -11,6 +11,8 @@ import ( func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.AtomicRenameEntryRequest) (*filer_pb.AtomicRenameEntryResponse, error) { + glog.V(1).Infof("AtomicRenameEntry %v", req) + ctx, err := fs.filer.BeginTransaction(ctx) if err != nil { return nil, err diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go index 13ec88d4a..414f19f0d 100644 --- a/weed/server/webdav_server.go +++ b/weed/server/webdav_server.go @@ -323,9 +323,13 @@ func (fs *WebDavFileSystem) Rename(ctx context.Context, oldName, newName string) if err != nil { return os.ErrExist } - if of.IsDir() && !strings.HasSuffix(oldName, "/") { - oldName += "/" - newName += "/" + if of.IsDir() { + if strings.HasSuffix(oldName, "/") { + oldName = strings.TrimRight(oldName, "/") + } + if strings.HasSuffix(newName, "/") { + newName = strings.TrimRight(newName, "/") + } } _, err = fs.stat(ctx, newName) @@ -363,10 +367,10 @@ func (fs *WebDavFileSystem) stat(ctx context.Context, fullFilePath string) (os.F var fi FileInfo entry, err := filer2.GetEntry(ctx, fs, fullFilePath) + if entry == nil { + return nil, os.ErrNotExist + } if err != nil { - if err == filer2.ErrNotFound { - return nil, os.ErrNotExist - } return nil, err } fi.size = int64(filer2.TotalSize(entry.GetChunks())) @@ -401,6 +405,9 @@ func (f *WebDavFile) Write(buf []byte) (int, error) { f.entry, err = filer2.GetEntry(ctx, f.fs, f.name) } + if f.entry == nil { + return 0, err + } if err != nil { return 0, err } @@ -493,6 +500,9 @@ func (f *WebDavFile) Read(p []byte) (readSize int, err error) { if f.entry == nil { f.entry, err = filer2.GetEntry(ctx, f.fs, f.name) } + if f.entry == nil { + return 0, err + } if err != nil { return 0, err }