frostfs-node/pkg/local_object_storage/blobstor/delete.go
Leonard Lyubich b127607ac6 [#176] localstore: Implement primary BlobStor
Implement primary local BLOB storage based on filesystem tree.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-12-11 17:19:37 +03:00

54 lines
1.1 KiB
Go

package blobstor
import (
"os"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/pkg/errors"
)
// DeletePrm groups the parameters of Delete operation.
type DeletePrm struct {
addr *objectSDK.Address
}
// DeleteRes groups resulting values of Delete operation.
type DeleteRes struct{}
// WithAddress is a Delete option to set the address of the object to delete.
//
// Option is required.
func (p *DeletePrm) WithAddress(addr *objectSDK.Address) *DeletePrm {
if p != nil {
p.addr = addr
}
return p
}
// Delete removes object from BLOB storage.
//
// Returns any error encountered that did not allow
// to completely remove the object.
func (b *BlobStor) Delete(prm *DeletePrm) (*DeleteRes, error) {
b.mtx.Lock()
defer b.mtx.Unlock()
err := b.fsTree.delete(prm.addr)
if errors.Is(err, errFileNotFound) {
err = nil
}
return nil, err
}
func (t *fsTree) delete(addr *object.Address) error {
p := t.treePath(addr)
if _, err := os.Stat(p); os.IsNotExist(err) {
return errFileNotFound
}
return os.Remove(p)
}