Don't try to read non-existant files in _verify_header_content.

If you're trying to upload a series of CLs, each is run through the
verification hooks before they're actually sent to the server. In
_verify_header_content, it first gets a list of files that are involved in the
CL, and then for each of them opens the file and checks for an appropriate
copyright header at the top.

The problem is, it opens the file from the filesystem directly, and that means
it will see whatever is in your current checkout, most likely the result of
the topmost CL, not the result of the CL its trying to verify.

This can be especially problematic when a file is changed and then later
deleted since the script will try to open a non-existant file. It won't just
check the wrong thing, it'll crash and fail. To avoid that particlar problem,
this change adds a check and skips over files that no longer exist.

Ideally what it would do is to actually retrieve the contents of the file in
question as it would appear after the CL that's being verified. That would
involve several extra calls to git which might add enough overhead to be
noticable, although there's a good chance it would be fast enough to not
matter. It also seems better to make sure the script won't crash right now and
then worry about a more complete/correct fix as time permits.

BUG=None
TEST=Ran repo upload on a branch where a file was modified and then deleted
and saw the verification script crash. Ran it again with this modification and
saw the crash go away.

Change-Id: I2f7110544d936c38ec3292bdfd1f9650659da93e
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/44167
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 60a772b..1da78d1 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -152,10 +152,11 @@
                         COMMON_EXCLUDED_PATHS)
 
   for f in files:
-    contents = open(f).read()
-    if len(contents) == 0: continue  # Ignore empty files
-    if not license_re.search(contents):
-      bad_files.append(f)
+    if os.path.exists(f): # Ignore non-existant files
+      contents = open(f).read()
+      if len(contents) == 0: continue  # Ignore empty files
+      if not license_re.search(contents):
+        bad_files.append(f)
   if bad_files:
      msg = "%s:\n%s\n%s" % (fail_msg, license_re.pattern,
                             "Found a bad header in these files:")