summaryrefslogtreecommitdiffstats
path: root/custodia/store
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-04-06 17:02:12 -0400
committerSimo Sorce <simo@redhat.com>2015-04-06 17:04:28 -0400
commit07ebcde1a29e80a21251cf2aad24909dbe760107 (patch)
treea4687af7c79f657ade73062cba024c7b4ea93726 /custodia/store
parentd2f4eb8ab433b45d503aa98e3028deab0c0b79c4 (diff)
downloadcustodia-07ebcde1a29e80a21251cf2aad24909dbe760107.tar.gz
custodia-07ebcde1a29e80a21251cf2aad24909dbe760107.tar.xz
custodia-07ebcde1a29e80a21251cf2aad24909dbe760107.zip
Fix sqlite's list() command
When listing do not add a / to the user filter it prevents matching key names with a prefix. When returning keys return a dict of key value pairs. If no values are available instead return None
Diffstat (limited to 'custodia/store')
-rw-r--r--custodia/store/sqlite.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/custodia/store/sqlite.py b/custodia/store/sqlite.py
index 9373ada..a76540e 100644
--- a/custodia/store/sqlite.py
+++ b/custodia/store/sqlite.py
@@ -56,12 +56,18 @@ class SqliteStore(CSStore):
def list(self, keyfilter='/'):
search = "SELECT * FROM %s WHERE key LIKE ?" % self.table
- key = os.path.join(keyfilter, '%')
+ key = "%s%%" % (keyfilter,)
try:
conn = sqlite3.connect(self.dburi)
r = conn.execute(search, (key,))
- value = r.fetchall()
+ rows = r.fetchall()
except sqlite3.Error as err:
log_error("Error listing (filter: %s): [%r]" % (key, repr(err)))
raise CSStoreError('Error occurred while trying to list keys')
- return value
+ if len(rows) > 0:
+ value = dict()
+ for row in rows:
+ value[row[0]] = row[1]
+ return value
+ else:
+ return None