fix: 解决 ClamAV 卸载后定时任务无法停止的问题 (#6143)

Refs #6100
This commit is contained in:
ssongliu 2024-08-15 23:16:30 +08:00 committed by GitHub
parent aa222aac31
commit 34e14636d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,6 +81,7 @@ func (c *ClamService) LoadBaseInfo() (dto.ClamBaseInfo, error) {
}
if !cmd.Which("clamdscan") {
baseInfo.IsActive = false
stopAllCronJob()
}
if baseInfo.IsActive {
@ -268,7 +269,8 @@ func (c *ClamService) Delete(req dto.ClamDelete) error {
}
func (c *ClamService) HandleOnce(req dto.OperateByID) error {
if cmd.Which("clamdscan") == false {
if !cmd.Which("clamdscan") {
stopAllCronJob()
return buserr.New("ErrClamdscanNotFound")
}
clam, _ := clamRepo.Get(commonRepo.WithByID(req.ID))
@ -473,6 +475,14 @@ func (c *ClamService) UpdateFile(req dto.UpdateByNameAndFile) error {
return nil
}
func stopAllCronJob() {
clams, _ := clamRepo.List(commonRepo.WithByStatus(constant.StatusEnable))
for i := 0; i < len(clams); i++ {
global.Cron.Remove(cron.EntryID(clams[i].EntryID))
_ = clamRepo.Update(clams[i].ID, map[string]interface{}{"status": constant.StatusDisable, "entry_id": 0})
}
}
func loadFileByName(name string) []string {
var logPaths []string
pathItem := path.Join(global.CONF.System.DataDir, resultDir, name)