From ff061c0d1d2d30909e201487cc72c106335ac3c6 Mon Sep 17 00:00:00 2001 From: tobiasjs Date: Wed, 17 Aug 2016 03:23:57 -0700 Subject: [PATCH] Do not assume that all presubmit directories still exist. In the case where a CL deletes the last file in the directory, it is listed in the presubmit files list, but the directory to which it refers will not exist, leading to os.listdir failing. BUG=638343 Review-Url: https://codereview.chromium.org/2250353003 --- presubmit_support.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index 2922b4e32..84a1f9bcf 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -1093,11 +1093,14 @@ def ListRelevantPresubmitFiles(files, root): # Look for PRESUBMIT.py in all candidate directories. results = [] for directory in sorted(list(candidates)): - for f in os.listdir(directory): - p = os.path.join(directory, f) - if os.path.isfile(p) and re.match( - r'PRESUBMIT.*\.py$', f) and not f.startswith('PRESUBMIT_test'): - results.append(p) + try: + for f in os.listdir(directory): + p = os.path.join(directory, f) + if os.path.isfile(p) and re.match( + r'PRESUBMIT.*\.py$', f) and not f.startswith('PRESUBMIT_test'): + results.append(p) + except OSError: + pass logging.debug('Presubmit files: %s', ','.join(results)) return results