From be53945f0eeaf26c3f2350f352308dc640bad707 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:07:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98=20(#3766?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/migration/migrations/v_1_9.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index c5f4f0547..00c1bc3c5 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -290,6 +290,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{ }).Error; err != nil { return err } + job.DefaultDownload = constant.Local } else { if err := tx.Model(&model.Cronjob{}). Where("id = ?", job.ID). @@ -299,11 +300,19 @@ var UpdateCronjobSpec = &gormigrate.Migration{ }).Error; err != nil { return err } + job.DefaultDownload = mapAccount[uint(job.TargetDirID)].Type } if job.Type != "directory" && job.Type != "database" && job.Type != "website" && job.Type != "app" && job.Type != "snapshot" && job.Type != "log" { continue } + itemPath := mapAccount[uint(job.TargetDirID)].BackupPath + if job.DefaultDownload == constant.Local || itemPath == "/" { + itemPath = "" + } else { + itemPath = strings.TrimPrefix(itemPath, "/") + "/" + } + var records []model.JobRecords _ = tx.Where("cronjob_id = ?", job.ID).Find(&records).Error for _, record := range records { @@ -325,12 +334,6 @@ var UpdateCronjobSpec = &gormigrate.Migration{ } continue } - itemPath := mapAccount[uint(job.TargetDirID)].BackupPath - if itemPath != "/" { - itemPath = strings.TrimPrefix(itemPath, "/") + "/" - } else { - itemPath = "" - } if job.Type == "log" { item := model.BackupRecord{ From: "cronjob", @@ -367,12 +370,12 @@ var UpdateCronjobSpec = &gormigrate.Migration{ files := strings.Split(record.File, ",") for _, file := range files { _ = tx.Model(&model.BackupRecord{}). - Where("file_dir = ? AND file_name = ?", path.Dir(file), path.Base(file)). + Where("file_dir = ? AND file_name = ?", path.Dir(strings.TrimPrefix(file, itemPath)), path.Base(file)). Updates(map[string]interface{}{"cronjob_id": job.ID, "from": "cronjob"}).Error } } else { _ = tx.Model(&model.BackupRecord{}). - Where("file_dir = ? AND file_name = ?", path.Dir(record.File), path.Base(record.File)). + Where("file_dir = ? AND file_name = ?", path.Dir(strings.TrimPrefix(record.File, itemPath)), path.Base(record.File)). Updates(map[string]interface{}{"cronjob_id": job.ID, "from": "cronjob"}).Error } }