-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncs_unix.go
More file actions
35 lines (29 loc) · 833 Bytes
/
funcs_unix.go
File metadata and controls
35 lines (29 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//go:build linux || darwin
// +build linux darwin
package main
import (
"fmt"
"path/filepath"
"strings"
"golang.org/x/sys/unix"
)
func (g *Getters) getDiskSpace(totalOrFreeSpace bool) (int64, error) {
var root = "/" // UNIX-like, simplified assumption
var stat unix.Statfs_t
if err := unix.Statfs(root, &stat); err != nil {
return 0, fmt.Errorf("failed to get filesystem stats: %w", err)
}
var bytes uint64
if totalOrFreeSpace { // True for total space, False for available space
bytes = stat.Blocks * uint64(stat.Bsize) // Total bytes
} else {
bytes = stat.Bavail * uint64(stat.Bsize) // Available bytes
}
return int64(bytes), nil
}
func hideFile(filename string) error {
return nil
}
func replaceSeparator(filePath string) string {
return strings.ReplaceAll(filePath, "\\", string(filepath.Separator))
}