From 34e14636d4f01da1184cb740d1ca7410fa56459c Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:16:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20ClamAV=20=E5=8D=B8?= =?UTF-8?q?=E8=BD=BD=E5=90=8E=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=81=9C=E6=AD=A2=E7=9A=84=E9=97=AE=E9=A2=98=20(#6143?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #6100 --- backend/app/service/clam.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/app/service/clam.go b/backend/app/service/clam.go index e54c4f3d5..5b685f5c4 100644 --- a/backend/app/service/clam.go +++ b/backend/app/service/clam.go @@ -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)