forked from TrueCloudLab/frostfs-node
[#970] fstree: Move delete implementation to a separate file
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
7f692409cf
commit
fb74524ac7
5 changed files with 52 additions and 25 deletions
|
@ -57,7 +57,7 @@ type FSTree struct {
|
|||
fileCounter FileCounter
|
||||
fileCounterEnabled bool
|
||||
|
||||
writeData func(string, []byte) error
|
||||
writer writer
|
||||
}
|
||||
|
||||
// Info groups the information about file storage.
|
||||
|
@ -95,7 +95,7 @@ func New(opts ...Option) *FSTree {
|
|||
for i := range opts {
|
||||
opts[i](f)
|
||||
}
|
||||
f.writeData = newGenericWriteData(f)
|
||||
f.writer = newGenericWriteData(f)
|
||||
|
||||
return f
|
||||
}
|
||||
|
@ -266,21 +266,7 @@ func (t *FSTree) Delete(ctx context.Context, prm common.DeletePrm) (common.Delet
|
|||
}
|
||||
|
||||
p := t.treePath(prm.Address)
|
||||
|
||||
if t.fileCounterEnabled {
|
||||
t.fileGuard.Lock(p)
|
||||
err = os.Remove(p)
|
||||
t.fileGuard.Unlock(p)
|
||||
if err == nil {
|
||||
t.fileCounter.Dec()
|
||||
}
|
||||
} else {
|
||||
err = os.Remove(p)
|
||||
}
|
||||
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
err = logicerr.Wrap(new(apistatus.ObjectNotFound))
|
||||
}
|
||||
err = t.writer.removeFile(p)
|
||||
return common.DeleteRes{}, err
|
||||
}
|
||||
|
||||
|
@ -357,7 +343,7 @@ func (t *FSTree) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, err
|
|||
}
|
||||
|
||||
size = len(prm.RawData)
|
||||
return common.PutRes{StorageID: []byte{}}, t.writeData(p, prm.RawData)
|
||||
return common.PutRes{StorageID: []byte{}}, t.writer.writeData(p, prm.RawData)
|
||||
}
|
||||
|
||||
// Get returns an object from the storage by address.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue