diff --git a/project.py b/project.py index 5a7a6ca8..18e1131d 100644 --- a/project.py +++ b/project.py @@ -1804,7 +1804,7 @@ class Project(object): return False if os.path.exists(tmpPath): - if curlret == 0 and os.stat(tmpPath).st_size > 16: + if curlret == 0 and self._IsValidBundle(tmpPath): os.rename(tmpPath, dstPath) return True else: @@ -1813,6 +1813,17 @@ class Project(object): else: return False + def _IsValidBundle(self, path): + try: + with open(path) as f: + if f.read(16) == '# v2 git bundle\n': + return True + else: + print("Invalid clone.bundle file; ignoring.", file=sys.stderr) + return False + except OSError: + return False + def _Checkout(self, rev, quiet=False): cmd = ['checkout'] if quiet: