From ceca078acb8607f5d3252356617cf630ff6b4be8 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 29 Nov 2018 00:00:56 -0800 Subject: [PATCH] avoid overwriting file or directory fix https://github.com/chrislusf/seaweedfs/issues/777 --- weed/filer2/filer.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go index 659054d86..0dde08d04 100644 --- a/weed/filer2/filer.go +++ b/weed/filer2/filer.go @@ -132,6 +132,12 @@ func (f *Filer) CreateEntry(entry *Entry) error { return fmt.Errorf("insert entry %s: %v", entry.FullPath, err) } } else { + if oldEntry.IsDirectory() && !entry.IsDirectory() { + return fmt.Errorf("existing %s is a directory", entry.FullPath) + } + if !oldEntry.IsDirectory() && entry.IsDirectory() { + return fmt.Errorf("existing %s is a file", entry.FullPath) + } if err := f.store.UpdateEntry(entry); err != nil { return fmt.Errorf("update entry %s: %v", entry.FullPath, err) }