Fix cache file

This commit is contained in:
世界
2023-07-19 20:40:34 +08:00
parent e075bb5c8d
commit 98bf696d01
3 changed files with 20 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package cachefile
import (
"net/netip"
"os"
"strings"
"sync"
"time"
@@ -40,6 +41,18 @@ func Open(path string, cacheID string) (*CacheFile, error) {
if cacheID != "" {
cacheIDBytes = append([]byte{0}, []byte(cacheID)...)
}
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
}
}
return nil
})
})
return &CacheFile{
DB: db,
cacheID: cacheIDBytes,