From 9532d0cba4f061b39ee6783dfb82c205f6df5834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 24 Jul 2023 16:50:26 +0800 Subject: [PATCH] Fix cache file --- experimental/clashapi/cachefile/cache.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/experimental/clashapi/cachefile/cache.go b/experimental/clashapi/cachefile/cache.go index adb4bc35..c282d715 100644 --- a/experimental/clashapi/cachefile/cache.go +++ b/experimental/clashapi/cachefile/cache.go @@ -45,11 +45,24 @@ func Open(path string, cacheID string) (*CacheFile, error) { } err = db.Batch(func(tx *bbolt.Tx) error { return tx.ForEach(func(name []byte, b *bbolt.Bucket) error { - bucketName := string(name) - if !(bucketName == string(bucketSelected) || strings.HasPrefix(bucketName, fakeipBucketPrefix)) { - delErr := tx.DeleteBucket(name) - if delErr != nil { - return delErr + if name[0] == 0 { + return b.ForEachBucket(func(k []byte) error { + bucketName := string(k) + if !(bucketName == string(bucketSelected)) { + delErr := b.DeleteBucket(name) + if delErr != nil { + return delErr + } + } + return nil + }) + } else { + bucketName := string(name) + if !(bucketName == string(bucketSelected) || strings.HasPrefix(bucketName, fakeipBucketPrefix)) { + delErr := tx.DeleteBucket(name) + if delErr != nil { + return delErr + } } } return nil