Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

绝大多数情况下创建文件夹、移动、重命名都不会影响空间占用,不需要删除缓存

if dirCache, exist := Cache.dirCache.Get(Key(storage, parentPath)); exist {
if newObj == nil {
t := time.Now()
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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()))
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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()))
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions internal/op/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此时Cache中还没有storage的容量信息,该语句产生的效果一定是什么也不做

return nil, err
}
Cache.SetStorageDetails(storage, ret)
Expand Down