[#31] fstree: Do not check for a file existence twice

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-01-25 16:53:10 +03:00 committed by fyrchik
parent abbecf49d6
commit dee4498c1e

View file

@ -191,15 +191,9 @@ func (t *FSTree) Delete(prm common.DeletePrm) (common.DeleteRes, error) {
return common.DeleteRes{}, common.ErrReadOnly return common.DeleteRes{}, common.ErrReadOnly
} }
p, err := t.getPath(prm.Address) p := t.treePath(prm.Address)
if err != nil {
if os.IsNotExist(err) {
err = logicerr.Wrap(apistatus.ObjectNotFound{})
}
return common.DeleteRes{}, err
}
err = os.Remove(p) err := os.Remove(p)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
err = logicerr.Wrap(apistatus.ObjectNotFound{}) err = logicerr.Wrap(apistatus.ObjectNotFound{})
} }
@ -209,7 +203,9 @@ func (t *FSTree) Delete(prm common.DeletePrm) (common.DeleteRes, error) {
// Exists returns the path to the file with object contents if it exists in the storage // Exists returns the path to the file with object contents if it exists in the storage
// and an error otherwise. // and an error otherwise.
func (t *FSTree) Exists(prm common.ExistsPrm) (common.ExistsRes, error) { func (t *FSTree) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
_, err := t.getPath(prm.Address) p := t.treePath(prm.Address)
_, err := os.Stat(p)
found := err == nil found := err == nil
if os.IsNotExist(err) { if os.IsNotExist(err) {
err = nil err = nil
@ -217,13 +213,6 @@ func (t *FSTree) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
return common.ExistsRes{Exists: found}, err return common.ExistsRes{Exists: found}, err
} }
func (t *FSTree) getPath(addr oid.Address) (string, error) {
p := t.treePath(addr)
_, err := os.Stat(p)
return p, err
}
// Put puts an object in the storage. // Put puts an object in the storage.
func (t *FSTree) Put(prm common.PutPrm) (common.PutRes, error) { func (t *FSTree) Put(prm common.PutPrm) (common.PutRes, error) {
if t.readOnly { if t.readOnly {