Mercurial > evolve
diff hgext3rd/pullbundle.py @ 4139:2bd652bece97
pullbundle: delay cache file opening
Otherwise we can end-up with a too many file open at the same time.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 25 Sep 2018 12:53:34 +0200 |
parents | cfdc6f55599b |
children | 9b71aa222f8e |
line wrap: on
line diff
--- 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)