Skip to content

Commit

Permalink
Merge branch 'master' into feat/reply
Browse files Browse the repository at this point in the history
  • Loading branch information
fy0 authored Oct 22, 2024
2 parents c7cc56f + 44bfc7d commit e6935d5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
golangci-lint run | reviewdog -reporter=github-pr-review -f=golangci-lint
golangci-lint run | reviewdog -reporter=github-pr-review -f=golangci-lint -filter-mode=nofilter -fail-on-error
18 changes: 15 additions & 3 deletions dice/dice_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sealdice-core/dice/model"
"sealdice-core/utils"
"sealdice-core/utils/crypto"
log "sealdice-core/utils/kratos"
)

const BackupDir = "./backups"
Expand Down Expand Up @@ -341,7 +342,7 @@ func (dm *DiceManager) BackupClean(fromAuto bool) (err error) {
return nil
}

// fmt.Println("开始定时清理备份", fromAuto)
log.Info("开始清理备份文件")

backupDir, err := os.Open(BackupDir)
if err != nil {
Expand Down Expand Up @@ -370,29 +371,40 @@ func (dm *DiceManager) BackupClean(fromAuto bool) (err error) {
sort.Sort(utils.ByModtime(fileInfos))

var fileInfoOld []os.FileInfo

logMsg := strings.Builder{}
logMsg.WriteString(fmt.Sprintf("现有备份文件 %d 个, 清理模式为 ", len(fileInfos)))

switch dm.BackupCleanStrategy {
case BackupCleanStrategyByCount:
logMsg.WriteString(fmt.Sprintf("保留一定数量(%d)", dm.BackupCleanKeepCount))
if len(fileInfos) > dm.BackupCleanKeepCount {
fileInfoOld = fileInfos[:len(fileInfos)-dm.BackupCleanKeepCount]
}
case BackupCleanStrategyByTime:
threshold := time.Now().Add(-dm.BackupCleanKeepDur)
logMsg.WriteString(fmt.Sprintf("保留一定时间(%v, %s)", dm.BackupCleanKeepDur, threshold.Format(time.DateTime)))
idx, _ := sort.Find(len(fileInfos), func(i int) int {
return threshold.Compare(fileInfos[i].ModTime())
})
fileInfoOld = fileInfos[:idx+1]
fileInfoOld = fileInfos[:idx]
default:
// no-op
}

logMsg.WriteString(fmt.Sprintf(", 有以下 %d 个将要被删除", len(fileInfoOld)))

errDel := []string{}
for _, fi := range fileInfoOld {
for i, fi := range fileInfoOld {
logMsg.WriteString(fmt.Sprintf("\n%d. %s", i+1, fi.Name()))
errDelete := os.Remove(filepath.Join(BackupDir, fi.Name()))
if errDelete != nil {
errDel = append(errDel, errDelete.Error())
}
}

log.Info(logMsg.String())

if len(errDel) > 0 {
return errors.New("error(s) occured when deleting files:\n" + strings.Join(errDel, "\n"))
}
Expand Down
7 changes: 2 additions & 5 deletions dice/dice_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,11 @@ func (dm *DiceManager) ResetBackupClean() {
dm.backupCleanCronID, err = dm.Cron.AddFunc(dm.BackupCleanCron, func() {
errBackup := dm.BackupClean(false)
if errBackup != nil {
fmt.Println("定时清理备份失败: ", errBackup.Error())
log.Errorf("定时清理备份失败: %v", errBackup)
}
})

if err != nil {
if len(dm.Dice) > 0 {
dm.Dice[0].Logger.Errorf("设定的备份清理cron有误: %q %v", dm.BackupCleanCron, err)
}
log.Errorf("设定的备份清理cron有误: %q %v", dm.BackupCleanCron, err)
return
}
}
Expand Down
2 changes: 0 additions & 2 deletions dice/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ func (i *ExtInfo) StorageInit() error {
// 使用互斥锁保护初始化过程,确保只初始化一次
i.dbMu.Lock()
defer i.dbMu.Unlock()
d.Logger.Debugf("[扩展]:%s 正在尝试获取锁进行初始化", i.Name)
if i.init {
d.Logger.Debug("[扩展]:初始化调用,但数据库已经加载")
// 如果已经初始化,则直接返回
return nil
}
Expand Down
12 changes: 3 additions & 9 deletions dice/platform_adapter_gocq.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,17 +1099,11 @@ func (pa *PlatformAdapterGocq) Serve() int {
}
}

socket.OnBinaryMessage = func(data []byte, socket gowebsocket.Socket) {
log.Debug("Recieved binary data ", data)
}
socket.OnBinaryMessage = func(_ /* data */ []byte, _ /* socket */ gowebsocket.Socket) {}

socket.OnPingReceived = func(data string, socket gowebsocket.Socket) {
log.Debug("Recieved ping " + data)
}
socket.OnPingReceived = func(_ /* data */ string, _ /* socket */ gowebsocket.Socket) {}

socket.OnPongReceived = func(data string, socket gowebsocket.Socket) {
log.Debug("Recieved pong " + data)
}
socket.OnPongReceived = func(_ /* data */ string, _ /* socket */ gowebsocket.Socket) {}

var lastDisconnect int64
socket.OnDisconnected = func(err error, socket gowebsocket.Socket) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.2
github.com/phuslu/log v1.0.88
github.com/pkg/errors v0.9.1
github.com/qustavo/sqlhooks/v2 v2.1.0
github.com/robfig/cron/v3 v3.0.1
github.com/sacOO7/gowebsocket v0.0.0-20221109081133-70ac927be105
github.com/sahilm/fuzzy v0.1.1
Expand Down Expand Up @@ -140,7 +141,6 @@ require (
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pdfcpu/pdfcpu v0.8.1 // indirect
github.com/qustavo/sqlhooks/v2 v2.1.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
Expand Down

0 comments on commit e6935d5

Please sign in to comment.