Attempting to remove a benchmark that does not exist will not delete the
database file.
Fixes bug #7158
---
src/secstate/main.py | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/secstate/main.py b/src/secstate/main.py
index 1b22d67..91c2937 100644
--- a/src/secstate/main.py
+++ b/src/secstate/main.py
@@ -300,12 +300,7 @@ class Secstate:
return True
def remove_content(self, benchmark_id):
- try:
- db_file = open(self.config.get('secstate',
'benchmark_database'), 'w')
- except IOError, e:
- self.log.error("Error writing changes to database: %(error)s" %
{'error':e})
- return False
-
+
if benchmark_id == 'all':
for key in self.database:
try:
@@ -315,11 +310,8 @@ class Secstate:
return False
self.database.clear()
- pickle.dump(self.database, db_file)
- db_file.close()
- return True
- if self.database.has_key(benchmark_id):
+ elif self.database.has_key(benchmark_id):
try:
shutil.rmtree(os.path.join(self.benchmark_dir, benchmark_id))
except (IOError, OSError), e:
@@ -327,13 +319,19 @@ class Secstate:
return False
del self.database[benchmark_id]
- pickle.dump(self.database, db_file)
- return True
else:
self.log.error("Could not find %(benchmark)s in database" %
{'benchmark':benchmark_id})
return False
+ try:
+ db_file = open(self.config.get('secstate',
'benchmark_database'), 'w')
+ except IOError, e:
+ self.log.error("Error writing changes to database: %(error)s" %
{'error':e})
+ return False
+ pickle.dump(self.database, db_file)
+ return True
+
def select(self, benchmark_id, item_id, selected):
"""
Function: Set the specified item to be selected, as well as its
subelements
--
1.7.0.1
Show replies by date