##// END OF EJS Templates
lfs: fix the stall and corruption issue when concurrently uploading blobs...
Matt Harbison -
r44746:43eea17a default
parent child Browse files
Show More
@@ -21,6 +21,7 b' from mercurial.pycompat import getattr'
21 from mercurial import (
21 from mercurial import (
22 encoding,
22 encoding,
23 error,
23 error,
24 httpconnection as httpconnectionmod,
24 node,
25 node,
25 pathutil,
26 pathutil,
26 pycompat,
27 pycompat,
@@ -94,28 +95,16 b' class nullvfs(lfsvfs):'
94 pass
95 pass
95
96
96
97
97 class lfsuploadfile(object):
98 class lfsuploadfile(httpconnectionmod.httpsendfile):
98 """a file-like object that supports __len__ and read.
99 """a file-like object that supports keepalive.
99 """
100 """
100
101
101 def __init__(self, fp):
102 def __init__(self, ui, filename):
102 self._fp = fp
103 super(lfsuploadfile, self).__init__(ui, filename, b'rb')
103 fp.seek(0, os.SEEK_END)
104 self.read = self._data.read
104 self._len = fp.tell()
105 fp.seek(0)
106
107 def __len__(self):
108 return self._len
109
105
110 def read(self, size):
106 def _makeprogress(self):
111 if self._fp is None:
107 return None # progress is handled by the worker client
112 return b''
113 return self._fp.read(size)
114
115 def close(self):
116 if self._fp is not None:
117 self._fp.close()
118 self._fp = None
119
108
120
109
121 class local(object):
110 class local(object):
@@ -507,10 +496,10 b' class _gitlfsremote(object):'
507
496
508 try:
497 try:
509 if action == b'upload':
498 if action == b'upload':
510 request.data = lfsuploadfile(localstore.open(oid))
499 request.data = lfsuploadfile(self.ui, localstore.path(oid))
511 request.get_method = lambda: 'PUT'
500 request.get_method = lambda: 'PUT'
512 request.add_header('Content-Type', 'application/octet-stream')
501 request.add_header('Content-Type', 'application/octet-stream')
513 request.add_header('Content-Length', len(request.data))
502 request.add_header('Content-Length', request.data.length)
514
503
515 with contextlib.closing(self.urlopener.open(request)) as res:
504 with contextlib.closing(self.urlopener.open(request)) as res:
516 contentlength = res.info().get(b"content-length")
505 contentlength = res.info().get(b"content-length")
General Comments 0
You need to be logged in to leave comments. Login now