-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
440 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
plugin "github.com/ipfs-force-community/damocles/manager-plugin" | ||
pluginfilestore "github.com/ipfs-force-community/damocles/manager-plugin/filestore" | ||
"github.com/shirou/gopsutil/disk" | ||
) | ||
|
||
var _ pluginfilestore.Store = (*Store)(nil) | ||
|
||
func OnInit(ctx context.Context, pluginsDir string, manifest *plugin.Manifest) error { | ||
return nil | ||
} | ||
|
||
func Open(cfg pluginfilestore.Config) (pluginfilestore.Store, error) { // nolint: deadcode | ||
dirPath, err := filepath.Abs(cfg.Path) | ||
if err != nil { | ||
return nil, fmt.Errorf("abs path for %s: %w", cfg.Path, err) | ||
} | ||
|
||
stat, err := os.Stat(dirPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("stat for %s: %w", dirPath, err) | ||
} | ||
|
||
if !stat.IsDir() { | ||
return nil, fmt.Errorf("%s is not a dir", dirPath) | ||
} | ||
|
||
cfg.Path = dirPath | ||
if cfg.Name == "" { | ||
cfg.Name = dirPath | ||
} | ||
|
||
return &Store{ | ||
cfg: cfg, | ||
}, nil | ||
} | ||
|
||
type Store struct { | ||
cfg pluginfilestore.Config | ||
} | ||
|
||
func (s *Store) Type() string { | ||
return "builtin-filesotre" | ||
} | ||
|
||
func (*Store) Version() string { | ||
return "example" | ||
} | ||
|
||
func (s *Store) Instance(context.Context) string { return s.cfg.Name } | ||
|
||
func (s *Store) InstanceConfig(_ context.Context) pluginfilestore.Config { | ||
return s.cfg | ||
} | ||
|
||
func (s *Store) InstanceInfo(ctx context.Context) (pluginfilestore.InstanceInfo, error) { | ||
usage, err := disk.UsageWithContext(ctx, s.cfg.Path) | ||
if err != nil { | ||
return pluginfilestore.InstanceInfo{}, fmt.Errorf("get disk usage: %w", err) | ||
} | ||
|
||
return pluginfilestore.InstanceInfo{ | ||
Config: s.cfg, | ||
Type: usage.Fstype, | ||
Total: usage.Total, | ||
Free: usage.Free, | ||
Used: usage.Used, | ||
UsedPercent: usage.UsedPercent, | ||
}, nil | ||
} | ||
|
||
func (s *Store) SubPath(ctx context.Context, pathType pluginfilestore.PathType, sectorID *pluginfilestore.SectorID, custom *string) (subPath string, err error) { | ||
if pathType == pluginfilestore.PathTypeCustom { | ||
if custom == nil { | ||
return "", fmt.Errorf("sectorID cannot be nil") | ||
} | ||
return *custom, nil | ||
} | ||
|
||
if sectorID == nil { | ||
return "", fmt.Errorf("sectorID cannot be nil") | ||
} | ||
|
||
sid := abi.SectorID{ | ||
Miner: abi.ActorID(sectorID.Miner), | ||
Number: abi.SectorNumber(sectorID.Number), | ||
} | ||
|
||
return filepath.Join(string(pathType), FormatSectorID(sid)), nil | ||
} | ||
|
||
const sectorIDFormat = "s-t0%d-%d" | ||
|
||
func FormatSectorID(sid abi.SectorID) string { | ||
return fmt.Sprintf(sectorIDFormat, sid.Miner, sid.Number) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module github.com/ipfs-force-community/damocles/manager-plugin/examples/examplefstore | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/filecoin-project/go-state-types v0.11.1 | ||
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20230913074304-520ac6d716fa | ||
github.com/shirou/gopsutil v2.18.12+incompatible | ||
) | ||
|
||
require ( | ||
github.com/StackExchange/wmi v1.2.1 // indirect | ||
github.com/filecoin-project/go-address v1.1.0 // indirect | ||
github.com/go-ole/go-ole v1.2.6 // indirect | ||
github.com/ipfs/go-block-format v0.1.2 // indirect | ||
github.com/ipfs/go-cid v0.4.1 // indirect | ||
github.com/ipfs/go-ipfs-util v0.0.3 // indirect | ||
github.com/ipfs/go-ipld-cbor v0.0.6 // indirect | ||
github.com/ipfs/go-ipld-format v0.5.0 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect | ||
github.com/minio/sha256-simd v1.0.1 // indirect | ||
github.com/mr-tron/base58 v1.2.0 // indirect | ||
github.com/multiformats/go-base32 v0.1.0 // indirect | ||
github.com/multiformats/go-base36 v0.2.0 // indirect | ||
github.com/multiformats/go-multibase v0.2.0 // indirect | ||
github.com/multiformats/go-multihash v0.2.3 // indirect | ||
github.com/multiformats/go-varint v0.0.7 // indirect | ||
github.com/polydawn/refmt v0.89.0 // indirect | ||
github.com/spaolacci/murmur3 v1.1.0 // indirect | ||
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect | ||
golang.org/x/crypto v0.10.0 // indirect | ||
golang.org/x/sys v0.9.0 // indirect | ||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect | ||
lukechampine.com/blake3 v1.2.1 // indirect | ||
) |
Oops, something went wrong.