2020-03-11 01:57:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-03-13 01:37:38 +00:00
|
|
|
"context"
|
|
|
|
|
2020-08-30 18:28:58 +00:00
|
|
|
"github.com/mitchellh/go-homedir"
|
|
|
|
"golang.org/x/xerrors"
|
2020-03-23 11:40:02 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
2020-08-30 18:28:58 +00:00
|
|
|
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
2020-09-07 14:12:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
2020-03-11 21:23:16 +00:00
|
|
|
)
|
2020-03-11 01:57:52 +00:00
|
|
|
|
2020-03-24 23:37:40 +00:00
|
|
|
type worker struct {
|
2020-08-17 13:26:18 +00:00
|
|
|
*sectorstorage.LocalWorker
|
2020-08-30 18:28:58 +00:00
|
|
|
|
|
|
|
localStore *stores.Local
|
|
|
|
ls stores.LocalStorage
|
2020-03-11 01:57:52 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 01:37:38 +00:00
|
|
|
func (w *worker) Version(context.Context) (build.Version, error) {
|
2020-09-08 18:54:37 +00:00
|
|
|
return build.WorkerAPIVersion, nil
|
2020-03-13 01:37:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 18:28:58 +00:00
|
|
|
func (w *worker) StorageAddLocal(ctx context.Context, path string) error {
|
|
|
|
path, err := homedir.Expand(path)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("expanding local path: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.localStore.OpenPath(ctx, path); err != nil {
|
|
|
|
return xerrors.Errorf("opening local path: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.ls.SetStorage(func(sc *stores.StorageConfig) {
|
|
|
|
sc.StoragePaths = append(sc.StoragePaths, stores.LocalPath{Path: path})
|
|
|
|
}); err != nil {
|
|
|
|
return xerrors.Errorf("get storage config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-07 14:12:46 +00:00
|
|
|
var _ storiface.WorkerCalls = &worker{}
|