From d78f6866ffcbaa47a06b2bdc204d5be2cae478b9 Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Mon, 24 Aug 2015 11:30:46 +0200
Subject: [PATCH 2/3] Skip files unrecognized by the 'oscap info' command
(#1255075)
If a file is unrecognized by the 'oscap info' command (not a SCAP document), it
returns a non-zero exit code. Such files are not important for us, so let's just
ignore them.
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
---
org_fedora_oscap/content_handling.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/org_fedora_oscap/content_handling.py b/org_fedora_oscap/content_handling.py
index c88b8f1..0921ad9 100644
--- a/org_fedora_oscap/content_handling.py
+++ b/org_fedora_oscap/content_handling.py
@@ -92,10 +92,14 @@ def explore_content_files(fpaths):
"""
def get_doc_type(file_path):
- for line in execReadlines("oscap", ["info", file_path]):
- if line.startswith("Document type:"):
- _prefix, _sep, type_info = line.partition(":")
- return type_info.strip()
+ try:
+ for line in execReadlines("oscap", ["info", file_path]):
+ if line.startswith("Document type:"):
+ _prefix, _sep, type_info = line.partition(":")
+ return type_info.strip()
+ except OSError:
+ # 'oscap info' exitted with a non-zero exit code -> unknown doc type
+ return None
xccdf_file = ""
cpe_file = ""
@@ -105,6 +109,8 @@ def explore_content_files(fpaths):
for fpath in fpaths:
doc_type = get_doc_type(fpath)
+ if not doc_type:
+ continue
# prefer DS over standalone XCCDF
if doc_type == "Source Data Stream" and (not xccdf_file or not found_ds):
--
2.1.0