comparison hgext/largefiles/remotestore.py @ 29218:fd288d118074

largefiles: send statlfile remote calls only for nonexisting locally files Files that are already in local store should be checked locally. The problem with this implementation is how difference in messages between local and remote checks should look like. For now local errors for file missing and content corrupted looks like this: 'changeset cset: filename references missing storepath\n' 'changeset cset: filename references corrupted storepath\n' for remote it looks like: 'changeset cset: filename missing\n' 'changeset cset: filename: contents differ\n' Contents differ error for remote calls is never raised currently - for now statlfile implementation lacks checking file content.
author liscju <piotr.listkiewicz@gmail.com>
date Mon, 09 May 2016 10:05:32 +0200
parents 305f9c36a0f5
children 0ccab84f9630
comparison
equal deleted inserted replaced
29217:2f9ad6ca19c2 29218:fd288d118074
12 urlerr = util.urlerr 12 urlerr = util.urlerr
13 urlreq = util.urlreq 13 urlreq = util.urlreq
14 14
15 import lfutil 15 import lfutil
16 import basestore 16 import basestore
17 import localstore
17 18
18 class remotestore(basestore.basestore): 19 class remotestore(basestore.basestore):
19 '''a largefile store accessed over a network''' 20 '''a largefile store accessed over a network'''
20 def __init__(self, ui, repo, url): 21 def __init__(self, ui, repo, url):
21 super(remotestore, self).__init__(ui, repo, url) 22 super(remotestore, self).__init__(ui, repo, url)
23 self._lstore = localstore.localstore(self.ui, self.repo, self.repo)
22 24
23 def put(self, source, hash): 25 def put(self, source, hash):
24 if self.sendfile(source, hash): 26 if self.sendfile(source, hash):
25 raise error.Abort( 27 raise error.Abort(
26 _('remotestore: could not put %s to remote store %s') 28 _('remotestore: could not put %s to remote store %s')
63 except IOError as e: 65 except IOError as e:
64 raise basestore.StoreError(filename, hash, self.url, str(e)) 66 raise basestore.StoreError(filename, hash, self.url, str(e))
65 67
66 return lfutil.copyandhash(chunks, tmpfile) 68 return lfutil.copyandhash(chunks, tmpfile)
67 69
70 def _hashesavailablelocally(self, hashes):
71 existslocallymap = self._lstore.exists(hashes)
72 localhashes = [hash for hash in hashes if existslocallymap[hash]]
73 return localhashes
74
68 def _verifyfiles(self, contents, filestocheck): 75 def _verifyfiles(self, contents, filestocheck):
69 failed = False 76 failed = False
70 expectedhashes = [expectedhash 77 expectedhashes = [expectedhash
71 for cset, filename, expectedhash in filestocheck] 78 for cset, filename, expectedhash in filestocheck]
72 stats = self._stat(expectedhashes) 79 localhashes = self._hashesavailablelocally(expectedhashes)
80 stats = self._stat([expectedhash for expectedhash in expectedhashes
81 if expectedhash not in localhashes])
82
73 for cset, filename, expectedhash in filestocheck: 83 for cset, filename, expectedhash in filestocheck:
74 stat = stats[expectedhash] 84 if expectedhash in localhashes:
75 if stat: 85 filetocheck = (cset, filename, expectedhash)
76 if stat == 1: 86 verifyresult = self._lstore._verifyfiles(contents,
77 self.ui.warn( 87 [filetocheck])
78 _('changeset %s: %s: contents differ\n') 88 if verifyresult:
79 % (cset, filename))
80 failed = True 89 failed = True
81 elif stat == 2: 90 else:
82 self.ui.warn( 91 stat = stats[expectedhash]
83 _('changeset %s: %s missing\n') 92 if stat:
84 % (cset, filename)) 93 if stat == 1:
85 failed = True 94 self.ui.warn(
86 else: 95 _('changeset %s: %s: contents differ\n')
87 raise RuntimeError('verify failed: unexpected response ' 96 % (cset, filename))
88 'from statlfile (%r)' % stat) 97 failed = True
98 elif stat == 2:
99 self.ui.warn(
100 _('changeset %s: %s missing\n')
101 % (cset, filename))
102 failed = True
103 else:
104 raise RuntimeError('verify failed: unexpected response '
105 'from statlfile (%r)' % stat)
89 return failed 106 return failed
90 107
91 def batch(self): 108 def batch(self):
92 '''Support for remote batching.''' 109 '''Support for remote batching.'''
93 return wireproto.remotebatch(self) 110 return wireproto.remotebatch(self)