aboutsummaryrefslogtreecommitdiffstats
path: root/anteater/src
diff options
context:
space:
mode:
authorlhinds <lhinds@redhat.com>2017-08-25 11:05:00 +0100
committerlhinds <lhinds@redhat.com>2017-08-25 11:05:00 +0100
commit5eb82911e0fb7dd2d5baa20d50c13fb7708b7fd4 (patch)
treec8c7dfcf695d58a71ecd8cfa8b7d3119498cbd5c /anteater/src
parent6248ecb0d79c3bb0ab31cd2a40222b246a8c206f (diff)
Handle missing / deleted / renamed files correctly.
Previously git rm or mv'ed files would be listed in the patchset. Anteater would then attempt to open the files and fail (as they don't exist). This patch resolves the issue by first not sys.exit'ing on a file not existing, and also not logging with ERROR level (which made the security audit job incorrectly fail). JIRA: RELENG-302 Change-Id: I6a0c56f691f4d80aca1b3509472c1d6e56d492e1 Signed-off-by: lhinds <lhinds@redhat.com>
Diffstat (limited to 'anteater/src')
-rw-r--r--anteater/src/patch_scan.py51
1 files changed, 26 insertions, 25 deletions
diff --git a/anteater/src/patch_scan.py b/anteater/src/patch_scan.py
index cd98523..ba0acdf 100644
--- a/anteater/src/patch_scan.py
+++ b/anteater/src/patch_scan.py
@@ -118,32 +118,33 @@ def scan_patch(project, patch_file, binary_list, file_audit_list,
try:
fo = open(patch_file, 'r')
lines = fo.readlines()
+ file_exists = True
except IOError:
- logger.error('%s does not exist', patch_file)
- sys.exit(1)
-
- for line in lines:
- for key, value in master_list.iteritems():
- regex = value['regex']
- desc = value['desc']
- if re.search(regex, line) and not re.search(project_list_re, line):
- logger.error('File contains violation: %s', patch_file)
- logger.error('Flagged Content: %s', line.rstrip())
- logger.error('Matched Regular Exp: %s', regex)
- logger.error('Rationale: %s', desc.rstrip())
- failure = True
- with open(reports_dir + "contents_" + project + ".log",
- "a") as gate_report:
- gate_report.write('File contains violation: {0}\n'.
- format(patch_file))
- gate_report.write('Flagged Content: {0}'.
- format(line))
- gate_report.write('Matched Regular Exp: {0}'.
- format(regex))
- gate_report.write('Rationale: {0}'.
- format(desc.rstrip()))
- # Run license check
- licence_check(project, licence_ext, licence_ignore, patch_file)
+ file_exists = False
+
+ if file_exists:
+ for line in lines:
+ for key, value in master_list.iteritems():
+ regex = value['regex']
+ desc = value['desc']
+ if re.search(regex, line) and not re.search(project_list_re, line):
+ logger.error('File contains violation: %s', patch_file)
+ logger.error('Flagged Content: %s', line.rstrip())
+ logger.error('Matched Regular Exp: %s', regex)
+ logger.error('Rationale: %s', desc.rstrip())
+ failure = True
+ with open(reports_dir + "contents_" + project + ".log",
+ "a") as gate_report:
+ gate_report.write('File contains violation: {0}\n'.
+ format(patch_file))
+ gate_report.write('Flagged Content: {0}'.
+ format(line))
+ gate_report.write('Matched Regular Exp: {0}'.
+ format(regex))
+ gate_report.write('Rationale: {0}'.
+ format(desc.rstrip()))
+ # Run license check
+ licence_check(project, licence_ext, licence_ignore, patch_file)
def licence_check(project, licence_ext,