From 9ae935d06acdab6a34245c3db061bde29312e96a Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 15 Sep 2023 15:28:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=80=A7=E8=83=BD=E8=B0=83=E6=95=B4=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=87=8D=E5=90=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#2308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #2301 --- backend/app/service/snapshot_create.go | 2 +- backend/utils/common/common.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/app/service/snapshot_create.go b/backend/app/service/snapshot_create.go index 4cdb098f2..0be39a23b 100644 --- a/backend/app/service/snapshot_create.go +++ b/backend/app/service/snapshot_create.go @@ -168,7 +168,7 @@ func snapCompress(snap snapHelper, rootDir string) { _ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"compress": err.Error()}) return } - size := common.LoadSizeUnit(float64(stat.Size())) + size := common.LoadSizeUnit2F(float64(stat.Size())) global.LOG.Debugf("compress successful! size of file: %s", size) snap.Status.Compress = constant.StatusDone snap.Status.Size = size diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index a9f3edea2..e0ecd7957 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -147,6 +147,16 @@ func RemoveRepeatElement(a interface{}) (ret []interface{}) { } func LoadSizeUnit(value float64) string { + if value > 1048576 { + return fmt.Sprintf("%vM", value/1048576) + } + if value > 1024 { + return fmt.Sprintf("%vK", value/1024) + } + return fmt.Sprintf("%v", value) +} + +func LoadSizeUnit2F(value float64) string { if value > 1073741824 { return fmt.Sprintf("%.2fG", value/1073741824) }