diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-11-29 00:07:54 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-11-29 00:07:54 -0800 |
| commit | 7a6f49cd420aad9416c4c99e53e621a43b3cd45e (patch) | |
| tree | 3daf2d7695d699ce141c32e562b8021dcbb06fe9 /weed/filer2/filer.go | |
| parent | ceca078acb8607f5d3252356617cf630ff6b4be8 (diff) | |
| download | seaweedfs-7a6f49cd420aad9416c4c99e53e621a43b3cd45e.tar.xz seaweedfs-7a6f49cd420aad9416c4c99e53e621a43b3cd45e.zip | |
refactor a bit more
fix https://github.com/chrislusf/seaweedfs/issues/777
Diffstat (limited to 'weed/filer2/filer.go')
| -rw-r--r-- | weed/filer2/filer.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go index 0dde08d04..8e8528e99 100644 --- a/weed/filer2/filer.go +++ b/weed/filer2/filer.go @@ -132,13 +132,7 @@ 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 { + if err := f.UpdateEntry(oldEntry, entry); err != nil { return fmt.Errorf("update entry %s: %v", entry.FullPath, err) } } @@ -150,7 +144,15 @@ func (f *Filer) CreateEntry(entry *Entry) error { return nil } -func (f *Filer) UpdateEntry(entry *Entry) (err error) { +func (f *Filer) UpdateEntry(oldEntry, entry *Entry) (err error) { + if oldEntry != nil { + 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) + } + } return f.store.UpdateEntry(entry) } |
