From b043388493335056de82a0ba9c307946f0113670 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 17 Sep 2023 11:43:46 +0800 Subject: [PATCH] =?UTF-8?q?edge-node=20cache.garbage=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=97=B6=E6=A3=80=E6=9F=A5Key=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=98=AF=E5=90=A6=E5=B7=B2=E5=8A=A0=E8=BD=BD=E5=AE=8C?= =?UTF-8?q?=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file.go | 9 +++++++++ internal/caches/storage_file.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/internal/caches/list_file.go b/internal/caches/list_file.go index b2c887e..c5d454b 100644 --- a/internal/caches/list_file.go +++ b/internal/caches/list_file.go @@ -379,6 +379,15 @@ func (this *FileList) GetDB(hash string) *FileListDB { return this.dbList[fnv.HashString(hash)%CountFileDB] } +func (this *FileList) HashMapIsLoaded() bool { + for _, db := range this.dbList { + if !db.HashMapIsLoaded() { + return false + } + } + return true +} + func (this *FileList) remove(hash string) (notFound bool, err error) { var db = this.GetDB(hash) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 328703a..78d3a69 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1534,6 +1534,10 @@ func (this *FileStorage) subDir(hash string) (dirPath string, dirIsFull bool) { // ScanGarbageCaches 清理目录中“失联”的缓存文件 // “失联”为不在HashMap中的文件 func (this *FileStorage) ScanGarbageCaches(fileCallback func(path string) error) error { + if !this.list.(*FileList).HashMapIsLoaded() { + return errors.New("cache list is loading") + } + var mainDir = this.options.Dir var allDirs = []string{mainDir} var subDirs = this.subDirs // copy