If an import of a benchmark fails, it will only delete the directory
with its id, not all benchmarks.
Fixes bug #7194
---
src/secstate/main.py | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/secstate/main.py b/src/secstate/main.py
index edca0f1..1a9aef4 100644
--- a/src/secstate/main.py
+++ b/src/secstate/main.py
@@ -215,7 +215,6 @@ class Secstate:
benchmark = oscap.xccdf_benchmark_import(benchmark_file)
if benchmark == None:
self.log.error("Error importing benchmark %(file)s" %
{'file':benchmark_file})
- shutil.rmtree(bench_dir)
return (None, None)
def_model = oscap.oval_definition_model_new()
@@ -230,7 +229,6 @@ class Secstate:
oscap.oval_definition_model_free(def_model)
oscap.oval_definition_model_free(tmp)
self.log.error('Error combining definition models')
- shutil.rmtree(bench_dir)
return (None, None)
oscap.oval_definition_model_free(tmp)
@@ -238,12 +236,15 @@ class Secstate:
if not oscap.oval_definition_model_is_valid(def_model):
self.log.error("Definition model is invalid")
oscap.oval_definition_model_free(def_model)
- shutil.rmtree(bench_dir)
return (None, None)
if store_path != None:
id = get_benchmark_id(benchmark_file)
directory = os.path.join(bench_dir, id)
+ if os.path.isdir(directory):
+ self.log.error("A benchmark named %(id)s already exists:
%(dir)s" % {'id':id, 'dir':directory})
+ return (None, None)
+
try:
os.mkdir(directory)
shutil.copy(benchmark_file, directory)
@@ -259,7 +260,7 @@ class Secstate:
shutil.copy(os.path.join(oval_path, oval), directory)
except (IOError, OSError), e:
self.log.error("Error importing content: %(error)s" %
{'error':e})
- shutil.rmtree(bench_dir)
+ shutil.rmtree(directory)
return (None, None)
return (benchmark, def_model)
--
1.7.1.1
Show replies by date