From fc2038e9293b8e23e9d9ca8b0e930b4819969116 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 2 Nov 2020 10:37:16 +0300 Subject: [PATCH] [#137] metabase: Implement Path method Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/metabase/db.go | 8 ++++++++ pkg/local_object_storage/metabase/db_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index b5cce3ab7c..90e624c433 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -8,6 +8,8 @@ import ( // DB represents local metabase of storage node. type DB struct { + path string + boltDB *bbolt.DB matchers map[object.SearchMatchType]func(string, string, string) bool @@ -16,6 +18,7 @@ type DB struct { // NewDB creates, initializes and returns DB instance. func NewDB(boltDB *bbolt.DB) *DB { return &DB{ + path: boltDB.Path(), boltDB: boltDB, matchers: map[object.SearchMatchType]func(string, string, string) bool{ object.MatchStringEqual: stringEqualMatcher, @@ -27,6 +30,11 @@ func (db *DB) Close() error { return db.boltDB.Close() } +// Path returns the path to meta database. +func (db *DB) Path() string { + return db.path +} + func stringEqualMatcher(key, objVal, filterVal string) bool { switch key { default: diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index 36b456d153..2b5104c43f 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -236,3 +236,19 @@ func TestDB_SelectProperties(t *testing.T) { fs.AddFilter(v2object.FilterPropertyChildfree, "some false value", objectSDK.MatchStringEqual) testSelect(t, db, fs, lnkAddr) } + +func TestDB_Path(t *testing.T) { + path := t.Name() + + bdb, err := bbolt.Open(path, 0600, nil) + require.NoError(t, err) + + defer func() { + bdb.Close() + os.Remove(path) + }() + + db := NewDB(bdb) + + require.Equal(t, path, db.Path()) +}