Fix cache file

This commit is contained in:
世界 2023-07-24 16:50:26 +08:00
parent cadc34f3ad
commit 9532d0cba4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -45,6 +45,18 @@ func Open(path string, cacheID string) (*CacheFile, error) {
} }
err = db.Batch(func(tx *bbolt.Tx) error { err = db.Batch(func(tx *bbolt.Tx) error {
return tx.ForEach(func(name []byte, b *bbolt.Bucket) error { return tx.ForEach(func(name []byte, b *bbolt.Bucket) error {
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) bucketName := string(name)
if !(bucketName == string(bucketSelected) || strings.HasPrefix(bucketName, fakeipBucketPrefix)) { if !(bucketName == string(bucketSelected) || strings.HasPrefix(bucketName, fakeipBucketPrefix)) {
delErr := tx.DeleteBucket(name) delErr := tx.DeleteBucket(name)
@ -52,6 +64,7 @@ func Open(path string, cacheID string) (*CacheFile, error) {
return delErr return delErr
} }
} }
}
return nil return nil
}) })
}) })