Skip to content

Commit

Permalink
Beta437 (#437)
Browse files Browse the repository at this point in the history
* beta430

* beta431

* beta432

* beta433

* beta434

* bet435

* beta436

* beta437
  • Loading branch information
Hoshinonyaruko authored Jun 25, 2024
1 parent 0c7dca9 commit 6c22ab3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions idmap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,39 @@ func InitializeDB() {
}
}

func ClearBucket(bucketName string) {
// 打开数据库文件
db, err := bbolt.Open(DBName, 0600, nil)
if err != nil {
log.Fatalf("Error opening DB: %v", err)
}
defer db.Close()

// 清空指定的bucket
err = db.Update(func(tx *bbolt.Tx) error {
// 获取指定的bucket
bucket := tx.Bucket([]byte(bucketName))
if bucket == nil {
return nil // 如果bucket不存在,直接返回nil
}

// 删除bucket中的所有键值对
err := bucket.ForEach(func(k, v []byte) error {
return bucket.Delete(k)
})
if err != nil {
return err
}
return nil
})

if err != nil {
log.Fatalf("Error clearing bucket %s: %v", bucketName, err)
} else {
mylog.Printf("ids清理成功.")
}
}

func CloseDB() {
db.Close()
}
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func main() {
// 定义faststart命令行标志。默认为false。
fastStart := flag.Bool("faststart", false, "start without initialization if set")
tidy := flag.Bool("tidy", false, "backup and tidy your config.yml")
c := flag.Bool("c", false, "clean ids bucket, must backup idmap.db first!")
m := flag.Bool("m", false, "Maintenance mode")

// 解析命令行参数到定义的标志。
Expand All @@ -63,6 +64,9 @@ func main() {
log.Println("配置文件已更新为新版,当前配置文件已备份.如产生问题请到群196173384反馈开发者。")
return
}
if *c {
idmap.ClearBucket("ids")
}
if _, err := os.Stat("config.yml"); os.IsNotExist(err) {
var ip string
var err error
Expand Down

0 comments on commit 6c22ab3

Please sign in to comment.