From aa057772dc3d57341d51501c802b9adddb82ceb3 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:38:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=AB=E7=85=A7?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#2286)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/snapshot.go | 9 +++++---- backend/app/service/snapshot_create.go | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 074ad9bce..ceaf76df2 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -71,13 +71,14 @@ func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error { } } for _, snap := range req.Names { - nameItems := strings.Split(snap, "_") - if !strings.HasPrefix(snap, "1panel_v") || !strings.HasSuffix(snap, ".tar.gz") || len(nameItems) != 3 { - return fmt.Errorf("incorrect snapshot name format of %s", snap) + shortName := strings.TrimPrefix(snap, "snapshot_") + nameItems := strings.Split(shortName, "_") + if !strings.HasPrefix(shortName, "1panel_v") || !strings.HasSuffix(shortName, ".tar.gz") || len(nameItems) != 3 { + return fmt.Errorf("incorrect snapshot name format of %s", shortName) } formatTime, err := time.Parse("20060102150405", strings.ReplaceAll(nameItems[2], ".tar.gz", "")) if err != nil { - return fmt.Errorf("incorrect snapshot name format of %s", snap) + return fmt.Errorf("incorrect snapshot name format of %s", shortName) } if strings.HasSuffix(snap, ".tar.gz") { snap = strings.ReplaceAll(snap, ".tar.gz", "") diff --git a/backend/app/service/snapshot_create.go b/backend/app/service/snapshot_create.go index a601b1e76..4cdb098f2 100644 --- a/backend/app/service/snapshot_create.go +++ b/backend/app/service/snapshot_create.go @@ -171,6 +171,7 @@ func snapCompress(snap snapHelper, rootDir string) { size := common.LoadSizeUnit(float64(stat.Size())) global.LOG.Debugf("compress successful! size of file: %s", size) snap.Status.Compress = constant.StatusDone + snap.Status.Size = size _ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"compress": constant.StatusDone, "size": size}) }