A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1// SiYuan - Refactor your thinking
2// Copyright (c) 2020-present, b3log.org
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Affero General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Affero General Public License for more details.
13//
14// You should have received a copy of the GNU Affero General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//go:build !ios && !android
18
19package util
20
21import (
22 "github.com/88250/go-humanize"
23 "github.com/shirou/gopsutil/v4/disk"
24 "github.com/siyuan-note/logging"
25)
26
27func NeedWarnDiskUsage(dataSize int64) bool {
28 usage, err := disk.Usage(WorkspaceDir)
29 if err != nil {
30 logging.LogErrorf("get disk usage failed: %s", err)
31 return false
32 }
33 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))
34 return usage.Free < uint64(dataSize*2)
35}
36
37func GetDiskUsage(p string) (total, used, free uint64) {
38 usage, err := disk.Usage(p)
39 if err != nil {
40 logging.LogErrorf("get disk usage failed: %s", err)
41 return
42 }
43 return usage.Total, usage.Used, usage.Free
44}