-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(storage): invalid storage details cache after writing operations #2018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,6 +349,7 @@ func MakeDir(ctx context.Context, storage driver.Driver, path string) error { | |
| if storage.Config().NoCache { | ||
| return nil, nil | ||
| } | ||
| Cache.InvalidateStorageDetails(storage) | ||
| if dirCache, exist := Cache.dirCache.Get(Key(storage, parentPath)); exist { | ||
| if newObj == nil { | ||
| t := time.Now() | ||
|
|
@@ -416,6 +417,7 @@ func Move(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string | |
| Cache.linkCache.DeleteKey(stdpath.Join(dstKey, srcRawObj.GetName())) | ||
| } | ||
| if !storage.Config().NoCache { | ||
| Cache.InvalidateStorageDetails(storage) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
| if cache, exist := Cache.dirCache.Get(srcKey); exist { | ||
| if srcRawObj.IsDir() { | ||
| Cache.deleteDirectoryTree(stdpath.Join(srcKey, srcRawObj.GetName())) | ||
|
|
@@ -479,6 +481,7 @@ func Rename(ctx context.Context, storage driver.Driver, srcPath, dstName string) | |
| Cache.linkCache.DeleteKey(stdpath.Join(dirKey, dstName)) | ||
| } | ||
| if !storage.Config().NoCache { | ||
| Cache.InvalidateStorageDetails(storage) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
| if cache, exist := Cache.dirCache.Get(dirKey); exist { | ||
| if srcRawObj.IsDir() { | ||
| Cache.deleteDirectoryTree(stdpath.Join(dirKey, srcRawObj.GetName())) | ||
|
|
@@ -547,6 +550,7 @@ func Copy(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string | |
| Cache.linkCache.DeleteKey(stdpath.Join(dstKey, srcRawObj.GetName())) | ||
| } | ||
| if !storage.Config().NoCache { | ||
| Cache.InvalidateStorageDetails(storage) | ||
| if cache, exist := Cache.dirCache.Get(dstKey); exist { | ||
| if newObj == nil { | ||
| newObj = &model.ObjWrapMask{Obj: srcRawObj, Mask: model.Temp} | ||
|
|
@@ -595,6 +599,7 @@ func Remove(ctx context.Context, storage driver.Driver, path string) error { | |
| err = s.Remove(ctx, model.UnwrapObjName(rawObj)) | ||
| if err == nil { | ||
| Cache.removeDirectoryObject(storage, dirPath, rawObj) | ||
| Cache.InvalidateStorageDetails(storage) | ||
| } | ||
| default: | ||
| return errs.NotImplement | ||
|
|
@@ -674,6 +679,7 @@ func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file mod | |
| if err == nil { | ||
| Cache.linkCache.DeleteKey(Key(storage, dstPath)) | ||
| if !storage.Config().NoCache { | ||
| Cache.InvalidateStorageDetails(storage) | ||
| if cache, exist := Cache.dirCache.Get(Key(storage, dstDirPath)); exist { | ||
| if newObj == nil { | ||
| newObj = &model.Object{ | ||
|
|
@@ -742,6 +748,7 @@ func PutURL(ctx context.Context, storage driver.Driver, dstDirPath, dstName, url | |
| if err == nil { | ||
| Cache.linkCache.DeleteKey(Key(storage, dstPath)) | ||
| if !storage.Config().NoCache { | ||
| Cache.InvalidateStorageDetails(storage) | ||
| if cache, exist := Cache.dirCache.Get(Key(storage, dstDirPath)); exist { | ||
| if newObj == nil { | ||
| t := time.Now() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -481,6 +481,7 @@ func GetStorageDetails(ctx context.Context, storage driver.Driver, refresh ...bo | |
| details, err, _ := detailsG.Do(storage.GetStorage().MountPath, func() (*model.StorageDetails, error) { | ||
| ret, err := wd.GetDetails(ctx) | ||
| if err != nil { | ||
| Cache.InvalidateStorageDetails(storage) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此时 |
||
| return nil, err | ||
| } | ||
| Cache.SetStorageDetails(storage, ret) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
绝大多数情况下创建文件夹、移动、重命名都不会影响空间占用,不需要删除缓存