From 5eb82911e0fb7dd2d5baa20d50c13fb7708b7fd4 Mon Sep 17 00:00:00 2001 From: lhinds Date: Fri, 25 Aug 2017 11:05:00 +0100 Subject: 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 --- anteater/src/patch_scan.py | 51 +++++++++++++++++++++++----------------------- 1 file 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, -- cgit 1.2.3-korg