forked from TrueCloudLab/frostfs-node
[#176] localstore: Implement primary BlobStor
Implement primary local BLOB storage based on filesystem tree. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
09750484f9
commit
b127607ac6
9 changed files with 467 additions and 0 deletions
54
pkg/local_object_storage/blobstor/delete.go
Normal file
54
pkg/local_object_storage/blobstor/delete.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue