pullbundle: delay cache file opening
Otherwise we can end-up with a too many file open at the same time.
--- 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)