-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
localstorage.go
44 lines (37 loc) · 1.04 KB
/
localstorage.go
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
36
37
38
39
40
41
42
43
44
package paths
import (
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/storage/sealer/fsutil"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
)
type BasicLocalStorage struct {
PathToJSON string
}
var _ LocalStorage = &BasicLocalStorage{}
func (ls *BasicLocalStorage) GetStorage() (storiface.StorageConfig, error) {
var def storiface.StorageConfig
c, err := config.StorageFromFile(ls.PathToJSON, &def)
if err != nil {
return storiface.StorageConfig{}, err
}
return *c, nil
}
func (ls *BasicLocalStorage) SetStorage(f func(*storiface.StorageConfig)) error {
var def storiface.StorageConfig
c, err := config.StorageFromFile(ls.PathToJSON, &def)
if err != nil {
return err
}
f(c)
return config.WriteStorageFile(ls.PathToJSON, *c)
}
func (ls *BasicLocalStorage) Stat(path string) (fsutil.FsStat, error) {
return fsutil.Statfs(path)
}
func (ls *BasicLocalStorage) DiskUsage(path string) (int64, error) {
si, err := fsutil.FileSize(path)
if err != nil {
return 0, err
}
return si.OnDisk, nil
}