comparison 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
comparison
equal deleted inserted replaced
4138:cfdc6f55599b 4139:2bd652bece97
381 return repo.cachevfs.join('pullbundles') 381 return repo.cachevfs.join('pullbundles')
382 382
383 def getcache(repo, bundlename): 383 def getcache(repo, bundlename):
384 cdir = cachedir(repo) 384 cdir = cachedir(repo)
385 bundlepath = os.path.join(cdir, bundlename) 385 bundlepath = os.path.join(cdir, bundlename)
386 try: 386 if not os.path.exists(bundlepath):
387 fd = open(bundlepath, 'rb')
388 return util.filechunkiter(fd)
389 except IOError as exc:
390 if exc.errno != errno.ENOENT:
391 raise
392 return None 387 return None
388 # delay file opening as much as possible this introduce a small race
389 # condition if someone remove the file before we actually use it. However
390 # opening too many file will not work.
391
392 def data():
393 with open(bundlepath, 'rb') as fd:
394 for chunk in util.filechunkiter(fd):
395 yield chunk
396 return data()
393 397
394 def cachewriter(repo, bundlename, stream): 398 def cachewriter(repo, bundlename, stream):
395 cdir = cachedir(repo) 399 cdir = cachedir(repo)
396 bundlepath = os.path.join(cdir, bundlename) 400 bundlepath = os.path.join(cdir, bundlename)
397 try: 401 try: