2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-03-15 19:40:31 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2020-09-21 14:31:31 +00:00
|
|
|
)
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
// ObjectStorage is an object storage interface.
|
|
|
|
type ObjectStorage interface {
|
|
|
|
// Put must save passed object
|
|
|
|
// and return any appeared error.
|
|
|
|
Put(o *objectSDK.Object) error
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
type localTarget struct {
|
2022-03-15 19:40:31 +00:00
|
|
|
storage ObjectStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *object.Object
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func (t *localTarget) WriteHeader(obj *object.Object) error {
|
2020-09-21 14:31:31 +00:00
|
|
|
t.obj = obj
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
|
2022-03-15 19:40:31 +00:00
|
|
|
if err := t.storage.Put(t.obj); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new(transformer.AccessIdentifiers).
|
2020-11-16 09:43:52 +00:00
|
|
|
WithSelfID(t.obj.ID()), nil
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|