From a72c92e55f3916cb38923c4b12a0370633c4c9ed Mon Sep 17 00:00:00 2001 From: Stepan Bujnak Date: Sat, 11 Mar 2017 02:52:04 -0800 Subject: [PATCH] Added locking on the filer move operation --- weed/filer/embedded_filer/filer_embedded.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/weed/filer/embedded_filer/filer_embedded.go b/weed/filer/embedded_filer/filer_embedded.go index 27299eb40..4a335058b 100644 --- a/weed/filer/embedded_filer/filer_embedded.go +++ b/weed/filer/embedded_filer/filer_embedded.go @@ -5,6 +5,7 @@ import ( "fmt" "path/filepath" "strings" + "sync" "github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/operation" @@ -14,6 +15,7 @@ type FilerEmbedded struct { master string directories *DirectoryManagerInMap files *FileListInLevelDb + mvMutex sync.Mutex } func NewFilerEmbedded(master string, dir string) (filer *FilerEmbedded, err error) { @@ -121,6 +123,9 @@ mv fromFile toDir mv fromFile toFile */ func (filer *FilerEmbedded) Move(fromPath string, toPath string) error { + filer.mvMutex.Lock() + defer filer.mvMutex.Unlock() + if _, dir_err := filer.FindDirectory(fromPath); dir_err == nil { if _, err := filer.FindDirectory(toPath); err == nil { // move folder under an existing folder