# HG changeset patch # User Pierre-Yves David # Date 1537872814 -7200 # Node ID 2bd652bece972da270f6ab45420fda31a98f691a # Parent cfdc6f55599b7f53b3c8c9c3131e626c87168bba pullbundle: delay cache file opening Otherwise we can end-up with a too many file open at the same time. 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)