diff -r cfdc6f55599b -r 2bd652bece97 hgext3rd/pullbundle.py --- a/hgext3rd/pullbundle.py Tue Sep 25 12:20:26 2018 +0200 +++ b/hgext3rd/pullbundle.py Tue Sep 25 12:53:34 2018 +0200 @@ -383,13 +383,17 @@ def getcache(repo, bundlename): cdir = cachedir(repo) bundlepath = os.path.join(cdir, bundlename) - try: - fd = open(bundlepath, 'rb') - return util.filechunkiter(fd) - except IOError as exc: - if exc.errno != errno.ENOENT: - raise + if not os.path.exists(bundlepath): return None + # delay file opening as much as possible this introduce a small race + # condition if someone remove the file before we actually use it. However + # opening too many file will not work. + + def data(): + with open(bundlepath, 'rb') as fd: + for chunk in util.filechunkiter(fd): + yield chunk + return data() def cachewriter(repo, bundlename, stream): cdir = cachedir(repo)