mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor a bit more
fix https://github.com/chrislusf/seaweedfs/issues/777
This commit is contained in:
parent
ceca078acb
commit
7a6f49cd42
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntr
|
|||
return &filer_pb.UpdateEntryResponse{}, err
|
||||
}
|
||||
|
||||
if err = fs.filer.UpdateEntry(newEntry); err == nil {
|
||||
if err = fs.filer.UpdateEntry(entry, newEntry); err == nil {
|
||||
fs.filer.DeleteChunks(unusedChunks)
|
||||
fs.filer.DeleteChunks(garbages)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue