weed filer: properly delete cached directory entry

fix https://github.com/chrislusf/seaweedfs/issues/910
This commit is contained in:
Chris Lu
2019-04-01 17:03:04 -07:00
parent 78b9db34d5
commit beaa2bd71a

View File

@@ -217,29 +217,32 @@ func (f *Filer) DeleteEntryMetaAndData(ctx context.Context, p FullPath, isRecurs
if err != nil { if err != nil {
return fmt.Errorf("list folder %s: %v", p, err) return fmt.Errorf("list folder %s: %v", p, err)
} }
if len(entries) == 0 { if len(entries) == 0 {
break break
} else { }
if isRecursive {
for _, sub := range entries { if isRecursive {
lastFileName = sub.Name() for _, sub := range entries {
f.DeleteEntryMetaAndData(ctx, sub.FullPath, isRecursive, shouldDeleteChunks) lastFileName = sub.Name()
limit-- err = f.DeleteEntryMetaAndData(ctx, sub.FullPath, isRecursive, shouldDeleteChunks)
if limit <= 0 { if err != nil {
break return err
}
} }
} else { limit--
if len(entries) > 0 { if limit <= 0 {
return fmt.Errorf("folder %s is not empty", p) break
} }
} }
f.cacheDelDirectory(string(p)) }
if len(entries) < 1024 {
break if len(entries) < 1024 {
} break
} }
} }
f.cacheDelDirectory(string(p))
} }
if shouldDeleteChunks { if shouldDeleteChunks {
@@ -264,6 +267,11 @@ func (f *Filer) ListDirectoryEntries(ctx context.Context, p FullPath, startFileN
} }
func (f *Filer) cacheDelDirectory(dirpath string) { func (f *Filer) cacheDelDirectory(dirpath string) {
if dirpath == "/" {
return
}
if f.directoryCache == nil { if f.directoryCache == nil {
return return
} }
@@ -272,6 +280,7 @@ func (f *Filer) cacheDelDirectory(dirpath string) {
} }
func (f *Filer) cacheGetDirectory(dirpath string) *Entry { func (f *Filer) cacheGetDirectory(dirpath string) *Entry {
if f.directoryCache == nil { if f.directoryCache == nil {
return nil return nil
} }