From dee4498c1eb975d81f6e2afcbfbf48803e8e3224 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 25 Jan 2023 16:53:10 +0300 Subject: [PATCH] [#31] fstree: Do not check for a file existence twice Signed-off-by: Evgenii Stratonikov --- .../blobstor/fstree/fstree.go | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index d129bf98..14d1db34 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -191,15 +191,9 @@ func (t *FSTree) Delete(prm common.DeletePrm) (common.DeleteRes, error) { return common.DeleteRes{}, common.ErrReadOnly } - p, err := t.getPath(prm.Address) - if err != nil { - if os.IsNotExist(err) { - err = logicerr.Wrap(apistatus.ObjectNotFound{}) - } - return common.DeleteRes{}, err - } + p := t.treePath(prm.Address) - err = os.Remove(p) + err := os.Remove(p) if err != nil && os.IsNotExist(err) { 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 // and an error otherwise. 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 if os.IsNotExist(err) { err = nil @@ -217,13 +213,6 @@ func (t *FSTree) Exists(prm common.ExistsPrm) (common.ExistsRes, error) { 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. func (t *FSTree) Put(prm common.PutPrm) (common.PutRes, error) { if t.readOnly {