2021-01-22 11:36:16 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2021-01-22 11:36:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerSizePrm struct {
|
2021-05-31 11:03:17 +00:00
|
|
|
cid *cid.ID
|
2021-01-22 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ContainerSizeRes struct {
|
|
|
|
size uint64
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func (p *ContainerSizePrm) WithContainerID(cid *cid.ID) *ContainerSizePrm {
|
2021-01-22 11:36:16 +00:00
|
|
|
if p != nil {
|
|
|
|
p.cid = cid
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ContainerSizeRes) Size() uint64 {
|
|
|
|
return r.size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) ContainerSize(prm *ContainerSizePrm) (*ContainerSizeRes, error) {
|
|
|
|
size, err := s.metaBase.ContainerSize(prm.cid)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get container size: %w", err)
|
2021-01-22 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &ContainerSizeRes{
|
|
|
|
size: size,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func ContainerSize(s *Shard, cid *cid.ID) (uint64, error) {
|
2021-01-22 11:36:16 +00:00
|
|
|
res, err := s.ContainerSize(&ContainerSizePrm{cid: cid})
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Size(), nil
|
|
|
|
}
|