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

Danield9351213dab9
diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go
index a63d416f16..4ab2fd8506 100644
--- a/kernel/bazaar/icon.go
+++ b/kernel/bazaar/icon.go
@@ -88,7 +88,7 @@ func Icons() (icons []*Icon) {
icon.Stars = repo.Stars
icon.OpenIssues = repo.OpenIssues
icon.Size = repo.Size
- icon.HSize = humanize.Bytes(uint64(icon.Size))
+ icon.HSize = humanize.BytesCustomCeil(uint64(icon.Size), 2)
icon.HUpdated = formatUpdated(icon.Updated)
pkg := bazaarIndex[strings.Split(repoURL, "@")[0]]
if nil != pkg {
@@ -158,7 +158,7 @@ func InstalledIcons() (ret []*Icon) {
icon.HInstallDate = info.ModTime().Format("2006-01-02")
installSize, _ := util.SizeOfDirectory(installPath)
icon.InstallSize = installSize
- icon.HInstallSize = humanize.Bytes(uint64(installSize))
+ icon.HInstallSize = humanize.BytesCustomCeil(uint64(installSize), 2)
readmeFilename := getPreferredReadme(icon.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go
index 5a5e5429a6..c8ecf3c401 100644
--- a/kernel/bazaar/plugin.go
+++ b/kernel/bazaar/plugin.go
@@ -93,7 +93,7 @@ func Plugins(frontend string) (plugins []*Plugin) {
plugin.Stars = repo.Stars
plugin.OpenIssues = repo.OpenIssues
plugin.Size = repo.Size
- plugin.HSize = humanize.Bytes(uint64(plugin.Size))
+ plugin.HSize = humanize.BytesCustomCeil(uint64(plugin.Size), 2)
plugin.HUpdated = formatUpdated(plugin.Updated)
pkg := bazaarIndex[strings.Split(repoURL, "@")[0]]
if nil != pkg {
@@ -196,7 +196,7 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) {
plugin.HInstallDate = info.ModTime().Format("2006-01-02")
installSize, _ := util.SizeOfDirectory(installPath)
plugin.InstallSize = installSize
- plugin.HInstallSize = humanize.Bytes(uint64(installSize))
+ plugin.HInstallSize = humanize.BytesCustomCeil(uint64(installSize), 2)
readmeFilename := getPreferredReadme(plugin.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go
index a60fc18db1..ef813b4ddf 100644
--- a/kernel/bazaar/template.go
+++ b/kernel/bazaar/template.go
@@ -89,7 +89,7 @@ func Templates() (templates []*Template) {
template.Stars = repo.Stars
template.OpenIssues = repo.OpenIssues
template.Size = repo.Size
- template.HSize = humanize.Bytes(uint64(template.Size))
+ template.HSize = humanize.BytesCustomCeil(uint64(template.Size), 2)
template.HUpdated = formatUpdated(template.Updated)
pkg := bazaarIndex[strings.Split(repoURL, "@")[0]]
if nil != pkg {
@@ -159,7 +159,7 @@ func InstalledTemplates() (ret []*Template) {
template.HInstallDate = info.ModTime().Format("2006-01-02")
installSize, _ := util.SizeOfDirectory(installPath)
template.InstallSize = installSize
- template.HInstallSize = humanize.Bytes(uint64(installSize))
+ template.HInstallSize = humanize.BytesCustomCeil(uint64(installSize), 2)
readmeFilename := getPreferredReadme(template.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go
index 57df50bdb4..a3d7fa7d2c 100644
--- a/kernel/bazaar/theme.go
+++ b/kernel/bazaar/theme.go
@@ -90,7 +90,7 @@ func Themes() (ret []*Theme) {
theme.Stars = repo.Stars
theme.OpenIssues = repo.OpenIssues
theme.Size = repo.Size
- theme.HSize = humanize.Bytes(uint64(theme.Size))
+ theme.HSize = humanize.BytesCustomCeil(uint64(theme.Size), 2)
theme.HUpdated = formatUpdated(theme.Updated)
pkg := bazaarIndex[strings.Split(repoURL, "@")[0]]
if nil != pkg {
@@ -160,7 +160,7 @@ func InstalledThemes() (ret []*Theme) {
theme.HInstallDate = info.ModTime().Format("2006-01-02")
installSize, _ := util.SizeOfDirectory(installPath)
theme.InstallSize = installSize
- theme.HInstallSize = humanize.Bytes(uint64(installSize))
+ theme.HInstallSize = humanize.BytesCustomCeil(uint64(installSize), 2)
readmeFilename := getPreferredReadme(theme.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go
index c0cf9cbb64..bea10a0fcd 100644
--- a/kernel/bazaar/widget.go
+++ b/kernel/bazaar/widget.go
@@ -89,7 +89,7 @@ func Widgets() (widgets []*Widget) {
widget.Stars = repo.Stars
widget.OpenIssues = repo.OpenIssues
widget.Size = repo.Size
- widget.HSize = humanize.Bytes(uint64(widget.Size))
+ widget.HSize = humanize.BytesCustomCeil(uint64(widget.Size), 2)
widget.HUpdated = formatUpdated(widget.Updated)
pkg := bazaarIndex[strings.Split(repoURL, "@")[0]]
if nil != pkg {
@@ -157,7 +157,7 @@ func InstalledWidgets() (ret []*Widget) {
widget.HInstallDate = info.ModTime().Format("2006-01-02")
installSize, _ := util.SizeOfDirectory(installPath)
widget.InstallSize = installSize
- widget.HInstallSize = humanize.Bytes(uint64(installSize))
+ widget.HInstallSize = humanize.BytesCustomCeil(uint64(installSize), 2)
readmeFilename := getPreferredReadme(widget.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
diff --git a/kernel/model/asset_content.go b/kernel/model/asset_content.go
index 072b6eeda5..c5ec26b4c7 100644
--- a/kernel/model/asset_content.go
+++ b/kernel/model/asset_content.go
@@ -508,7 +508,7 @@ func (parser *TxtAssetParser) Parse(absPath string) (ret *AssetParseResult) {
}
if TxtAssetContentMaxSize < info.Size() {
- logging.LogWarnf("text asset [%s] is too large [%s]", absPath, humanize.Bytes(uint64(info.Size())))
+ logging.LogWarnf("text asset [%s] is too large [%s]", absPath, humanize.BytesCustomCeil(uint64(info.Size()), 2))
return
}
@@ -836,16 +836,16 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
if maxSize, parseErr := strconv.ParseUint(maxSizeVal, 10, 64); nil == parseErr {
if maxSize != PDFAssetContentMaxSize {
PDFAssetContentMaxSize = maxSize
- logging.LogInfof("set PDF asset content index max size to [%s]", humanize.Bytes(maxSize))
+ logging.LogInfof("set PDF asset content index max size to [%s]", humanize.BytesCustomCeil(maxSize, 2))
}
} else {
- logging.LogWarnf("invalid env [SIYUAN_PDF_ASSET_CONTENT_INDEX_MAX_SIZE]: [%s], parsing failed: ", maxSizeVal, parseErr)
+ logging.LogWarnf("invalid env [SIYUAN_PDF_ASSET_CONTENT_INDEX_MAX_SIZE]: [%s], parsing failed: %s", maxSizeVal, parseErr)
}
}
if PDFAssetContentMaxSize < uint64(len(pdfData)) {
// PDF files larger than 128MB are not included in asset file content searching https://github.com/siyuan-note/siyuan/issues/9500
- logging.LogWarnf("ignore large PDF asset [%s] with [%s]", absPath, humanize.Bytes(uint64(len(pdfData))))
+ logging.LogWarnf("ignore large PDF asset [%s] with [%s]", absPath, humanize.BytesCustomCeil(uint64(len(pdfData)), 2))
return
}
diff --git a/kernel/model/index.go b/kernel/model/index.go
index b5d34e78f3..455e2ff4ad 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -203,7 +203,7 @@ func index(boxID string) {
box.UpdateHistoryGenerated() // 初始化历史生成时间为当前时间
end := time.Now()
elapsed := end.Sub(start).Seconds()
- logging.LogInfof("rebuilt database for notebook [%s] in [%.2fs], tree [count=%d, size=%s]", box.ID, elapsed, treeCount, humanize.Bytes(uint64(treeSize)))
+ logging.LogInfof("rebuilt database for notebook [%s] in [%.2fs], tree [count=%d, size=%s]", box.ID, elapsed, treeCount, humanize.BytesCustomCeil(uint64(treeSize), 2))
debug.FreeOSMemory()
return
}
diff --git a/kernel/model/ocr.go b/kernel/model/ocr.go
index ad6e7ecc2e..c082369596 100644
--- a/kernel/model/ocr.go
+++ b/kernel/model/ocr.go
@@ -136,7 +136,7 @@ func LoadAssetsTexts() {
debug.FreeOSMemory()
if elapsed := time.Since(start).Seconds(); 2 < elapsed {
- logging.LogWarnf("read assets texts [%s] to [%s], elapsed [%.2fs]", humanize.Bytes(uint64(len(data))), assetsTextsPath, elapsed)
+ logging.LogWarnf("read assets texts [%s] to [%s], elapsed [%.2fs]", humanize.BytesCustomCeil(uint64(len(data)), 2), assetsTextsPath, elapsed)
}
return
}
@@ -165,7 +165,7 @@ func SaveAssetsTexts() {
debug.FreeOSMemory()
if elapsed := time.Since(start).Seconds(); 2 < elapsed {
- logging.LogWarnf("save assets texts [size=%s] to [%s], elapsed [%.2fs]", humanize.Bytes(uint64(len(data))), assetsTextsPath, elapsed)
+ logging.LogWarnf("save assets texts [size=%s] to [%s], elapsed [%.2fs]", humanize.BytesCustomCeil(uint64(len(data)), 2), assetsTextsPath, elapsed)
}
util.AssetsTextsChanged.Store(false)
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index 5e87382c39..dc89ea428f 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -506,7 +506,7 @@ func InitBlockTree(force bool) {
p.Release()
elapsed := time.Since(start).Seconds()
- logging.LogInfof("read block tree [%s] to [%s], elapsed [%.2fs]", humanize.Bytes(uint64(size.Load())), util.BlockTreePath, elapsed)
+ logging.LogInfof("read block tree [%s] to [%s], elapsed [%.2fs]", humanize.BytesCustomCeil(uint64(size.Load()), 2), util.BlockTreePath, elapsed)
return
}
@@ -569,7 +569,7 @@ func SaveBlockTree(force bool) {
elapsed := time.Since(start).Seconds()
if 2 < elapsed {
- logging.LogWarnf("save block tree [size=%s] to [%s], elapsed [%.2fs]", humanize.Bytes(size), util.BlockTreePath, elapsed)
+ logging.LogWarnf("save block tree [size=%s] to [%s], elapsed [%.2fs]", humanize.BytesCustomCeil(size, 2), util.BlockTreePath, elapsed)
}
}
diff --git a/kernel/util/disk.go b/kernel/util/disk.go
index 0d1fa21c49..9feb8390b2 100644
--- a/kernel/util/disk.go
+++ b/kernel/util/disk.go
@@ -30,6 +30,6 @@ func NeedWarnDiskUsage(dataSize int64) bool {
logging.LogErrorf("get disk usage failed: %s", err)
return false
}
- logging.LogInfof("disk usage [total=%s, used=%s, free=%s]", humanize.Bytes(usage.Total), humanize.Bytes(usage.Used), humanize.Bytes(usage.Free))
+ logging.LogInfof("disk usage [total=%s, used=%s, free=%s]", humanize.BytesCustomCeil(usage.Total, 2), humanize.BytesCustomCeil(usage.Used, 2), humanize.BytesCustomCeil(usage.Free, 2))
return usage.Free < uint64(dataSize*2)
}
diff --git a/kernel/util/tesseract.go b/kernel/util/tesseract.go
index 25f8bd2989..256be5fd38 100644
--- a/kernel/util/tesseract.go
+++ b/kernel/util/tesseract.go
@@ -184,7 +184,7 @@ func InitTesseract() {
}
TesseractLangs = filterTesseractLangs(langs)
- logging.LogInfof("tesseract-ocr enabled [ver=%s, maxSize=%s, langs=%s]", ver, humanize.Bytes(TesseractMaxSize), strings.Join(TesseractLangs, "+"))
+ logging.LogInfof("tesseract-ocr enabled [ver=%s, maxSize=%s, langs=%s]", ver, humanize.BytesCustomCeil(TesseractMaxSize, 2), strings.Join(TesseractLangs, "+"))
tesseractInited.Store(true)
}