Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve disk usage display https://github.com/siyuan-note/siyuan/issues/11121

Danielffb44137f246
diff --git a/kernel/api/asset.go b/kernel/api/asset.go
index 8b51684bcc..ba7ef3599d 100644
--- a/kernel/api/asset.go
+++ b/kernel/api/asset.go
@@ -82,7 +82,7 @@ func statAsset(c *gin.Context) {
ret.Data = map[string]interface{}{
"size": info.Size(),
- "hSize": humanize.Bytes(uint64(info.Size())),
+ "hSize": humanize.BytesCustomCeil(uint64(info.Size()), 2),
"created": created,
"hCreated": hCreated,
"updated": updated,
diff --git a/kernel/model/asset_content.go b/kernel/model/asset_content.go
index 584e56f57e..072b6eeda5 100644
--- a/kernel/model/asset_content.go
+++ b/kernel/model/asset_content.go
@@ -236,7 +236,7 @@ func fromSQLAssetContent(assetContent *sql.AssetContent, beforeLen int) *AssetCo
Ext: assetContent.Ext,
Path: assetContent.Path,
Size: assetContent.Size,
- HSize: humanize.Bytes(uint64(assetContent.Size)),
+ HSize: humanize.BytesCustomCeil(uint64(assetContent.Size), 2),
Updated: assetContent.Updated,
Content: content,
}
diff --git a/kernel/model/box.go b/kernel/model/box.go
index 223d205704..a5daf0f291 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -73,7 +73,7 @@ func StatJob() {
Conf.m.Unlock()
Conf.Save()
- logging.LogInfof("auto stat [trees=%d, blocks=%d, dataSize=%s, assetsSize=%s]", Conf.Stat.TreeCount, Conf.Stat.BlockCount, humanize.Bytes(uint64(Conf.Stat.DataSize)), humanize.Bytes(uint64(Conf.Stat.AssetsSize)))
+ logging.LogInfof("auto stat [trees=%d, blocks=%d, dataSize=%s, assetsSize=%s]", Conf.Stat.TreeCount, Conf.Stat.BlockCount, humanize.BytesCustomCeil(uint64(Conf.Stat.DataSize), 2), humanize.BytesCustomCeil(uint64(Conf.Stat.AssetsSize), 2))
// 桌面端检查磁盘可用空间 https://github.com/siyuan-note/siyuan/issues/6873
if util.ContainerStd != util.Container {
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index f0b911c3d0..3361a8bba2 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -851,7 +851,7 @@ func InitBoxes() {
var dbSize string
if dbFile, err := os.Stat(util.DBPath); nil == err {
- dbSize = humanize.Bytes(uint64(dbFile.Size()))
+ dbSize = humanize.BytesCustomCeil(uint64(dbFile.Size()), 2)
}
logging.LogInfof("database size [%s], tree/block count [%d/%d]", dbSize, treenode.CountTrees(), treenode.CountBlocks())
}
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 57cdaa00a3..460141481c 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -90,7 +90,7 @@ func (box *Box) docFromFileInfo(fileInfo *FileInfo, ial map[string]string) (ret
t, _ := time.ParseInLocation("20060102150405", ret.ID[:14], time.Local)
ret.CTime = t.Unix()
ret.HCtime = t.Format("2006-01-02 15:04:05")
- ret.HSize = humanize.Bytes(ret.Size)
+ ret.HSize = humanize.BytesCustomCeil(ret.Size, 2)
mTime := t
if updated := ial["updated"]; "" != updated {
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index cf1008cebc..4d788c8d59 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -233,7 +233,7 @@ func DiffRepoSnapshots(left, right string) (ret *LeftRightDiff, err error) {
FileID: removeRight.ID,
Title: title,
Path: removeRight.Path,
- HSize: humanize.Bytes(uint64(removeRight.Size)),
+ HSize: humanize.BytesCustomCeil(uint64(removeRight.Size), 2),
Updated: removeRight.Updated,
})
}
@@ -251,7 +251,7 @@ func DiffRepoSnapshots(left, right string) (ret *LeftRightDiff, err error) {
FileID: addLeft.ID,
Title: title,
Path: addLeft.Path,
- HSize: humanize.Bytes(uint64(addLeft.Size)),
+ HSize: humanize.BytesCustomCeil(uint64(addLeft.Size), 2),
Updated: addLeft.Updated,
})
}
@@ -269,7 +269,7 @@ func DiffRepoSnapshots(left, right string) (ret *LeftRightDiff, err error) {
FileID: updateLeft.ID,
Title: title,
Path: updateLeft.Path,
- HSize: humanize.Bytes(uint64(updateLeft.Size)),
+ HSize: humanize.BytesCustomCeil(uint64(updateLeft.Size), 2),
Updated: updateLeft.Updated,
})
}
@@ -287,7 +287,7 @@ func DiffRepoSnapshots(left, right string) (ret *LeftRightDiff, err error) {
FileID: updateRight.ID,
Title: title,
Path: updateRight.Path,
- HSize: humanize.Bytes(uint64(updateRight.Size)),
+ HSize: humanize.BytesCustomCeil(uint64(updateRight.Size), 2),
Updated: updateRight.Updated,
})
}
@@ -500,7 +500,7 @@ func PurgeCloud() (err error) {
deletedIndexes := stat.Indexes
deletedObjects := stat.Objects
- deletedSize := humanize.Bytes(uint64(stat.Size))
+ deletedSize := humanize.BytesCustomCeil(uint64(stat.Size), 2)
msg = fmt.Sprintf(Conf.Language(232), deletedIndexes, deletedObjects, deletedSize)
util.PushMsg(msg, 5000)
return
@@ -523,7 +523,7 @@ func PurgeRepo() (err error) {
deletedIndexes := stat.Indexes
deletedObjects := stat.Objects
- deletedSize := humanize.Bytes(uint64(stat.Size))
+ deletedSize := humanize.BytesCustomCeil(uint64(stat.Size), 2)
msg = fmt.Sprintf(Conf.Language(203), deletedIndexes, deletedObjects, deletedSize)
util.PushMsg(msg, 5000)
return
@@ -696,7 +696,7 @@ func DownloadCloudSnapshot(tag, id string) (err error) {
if nil != err {
return
}
- msg := fmt.Sprintf(Conf.Language(153), downloadFileCount, downloadChunkCount, humanize.Bytes(uint64(downloadBytes)))
+ msg := fmt.Sprintf(Conf.Language(153), downloadFileCount, downloadChunkCount, humanize.BytesCustomCeil(uint64(downloadBytes), 2))
util.PushMsg(msg, 5000)
util.PushStatusBar(msg)
return
@@ -737,7 +737,7 @@ func UploadCloudSnapshot(tag, id string) (err error) {
err = errors.New(fmt.Sprintf(Conf.Language(84), formatRepoErrorMsg(err)))
return
}
- msg := fmt.Sprintf(Conf.Language(152), uploadFileCount, uploadChunkCount, humanize.Bytes(uint64(uploadBytes)))
+ msg := fmt.Sprintf(Conf.Language(152), uploadFileCount, uploadChunkCount, humanize.BytesCustomCeil(uint64(uploadBytes), 2))
util.PushMsg(msg, 5000)
util.PushStatusBar(msg)
return
@@ -1039,9 +1039,9 @@ func syncRepoDownload() (err error) {
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(err))
if errors.Is(err, dejavu.ErrCloudStorageSizeExceeded) {
u := Conf.GetUser()
- msg = fmt.Sprintf(Conf.Language(43), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(43), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
if 2 == u.UserSiYuanSubscriptionPlan {
- msg = fmt.Sprintf(Conf.Language(68), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(68), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
}
}
Conf.Sync.Stat = msg
@@ -1053,7 +1053,7 @@ func syncRepoDownload() (err error) {
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
Conf.Sync.Synced = util.CurrentTimeMillis()
- msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
+ msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.BytesCustomCeil(uint64(trafficStat.UploadBytes), 2), humanize.BytesCustomFloor(uint64(trafficStat.DownloadBytes), 2))
Conf.Sync.Stat = msg
Conf.Save()
autoSyncErrCount = 0
@@ -1110,9 +1110,9 @@ func syncRepoUpload() (err error) {
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(err))
if errors.Is(err, dejavu.ErrCloudStorageSizeExceeded) {
u := Conf.GetUser()
- msg = fmt.Sprintf(Conf.Language(43), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(43), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
if 2 == u.UserSiYuanSubscriptionPlan {
- msg = fmt.Sprintf(Conf.Language(68), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(68), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
}
}
Conf.Sync.Stat = msg
@@ -1124,7 +1124,7 @@ func syncRepoUpload() (err error) {
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
Conf.Sync.Synced = util.CurrentTimeMillis()
- msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
+ msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.BytesCustomCeil(uint64(trafficStat.UploadBytes), 2), humanize.BytesCustomCeil(uint64(trafficStat.DownloadBytes), 2))
Conf.Sync.Stat = msg
Conf.Save()
autoSyncErrCount = 0
@@ -1218,9 +1218,9 @@ func bootSyncRepo() (err error) {
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(err))
if errors.Is(err, dejavu.ErrCloudStorageSizeExceeded) {
u := Conf.GetUser()
- msg = fmt.Sprintf(Conf.Language(43), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(43), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
if 2 == u.UserSiYuanSubscriptionPlan {
- msg = fmt.Sprintf(Conf.Language(68), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(68), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
}
}
Conf.Sync.Stat = msg
@@ -1303,9 +1303,9 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(err))
if errors.Is(err, dejavu.ErrCloudStorageSizeExceeded) {
u := Conf.GetUser()
- msg = fmt.Sprintf(Conf.Language(43), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(43), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
if 2 == u.UserSiYuanSubscriptionPlan {
- msg = fmt.Sprintf(Conf.Language(68), humanize.Bytes(uint64(u.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(68), humanize.BytesCustomCeil(uint64(u.UserSiYuanRepoSize), 2))
}
}
Conf.Sync.Stat = msg
@@ -1324,7 +1324,7 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
Conf.Sync.Synced = util.CurrentTimeMillis()
- msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
+ msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.BytesCustomCeil(uint64(trafficStat.UploadBytes), 2), humanize.BytesCustomCeil(uint64(trafficStat.DownloadBytes), 2))
Conf.Sync.Stat = msg
Conf.Save()
autoSyncErrCount = 0
@@ -1341,7 +1341,7 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult, trafficStat *dejavu.TrafficStat, mode string, elapsed time.Duration) {
logging.LogInfof("synced data repo [device=%s, kernel=%s, provider=%d, mode=%s/%t, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs], merge result [conflicts=%d, upserts=%d, removes=%d]\n\n",
Conf.System.ID, KernelID, Conf.Sync.Provider, mode, byHand,
- trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)),
+ trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.BytesCustomCeil(uint64(trafficStat.UploadBytes), 2), humanize.BytesCustomCeil(uint64(trafficStat.DownloadBytes), 2),
elapsed.Seconds(),
len(mergeResult.Conflicts), len(mergeResult.Upserts), len(mergeResult.Removes))
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index 4c1decbf66..5c1d7c0fd2 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -543,13 +543,13 @@ func ListCloudSyncDir() (syncDirs []*Sync, hSize string, err error) {
CloudName: d.Name,
}
if conf.ProviderSiYuan == Conf.Sync.Provider {
- sync.HSize = humanize.Bytes(uint64(dirSize))
+ sync.HSize = humanize.BytesCustomCeil(uint64(dirSize), 2)
}
syncDirs = append(syncDirs, sync)
}
hSize = "-"
if conf.ProviderSiYuan == Conf.Sync.Provider {
- hSize = humanize.Bytes(uint64(size))
+ hSize = humanize.BytesCustomCeil(uint64(size), 2)
}
return
}