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) }