localstore.py
72 lines
| 2.4 KiB
| text/x-python
|
PythonLexer
|
r15168 | # Copyright 2009-2010 Gregory P. Ward | ||
# Copyright 2009-2010 Intelerad Medical Systems Incorporated | ||||
# Copyright 2010-2011 Fog Creek Software | ||||
# Copyright 2010-2011 Unity Technologies | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
|
r15252 | '''store class for local filesystem''' | ||
|
r29310 | from __future__ import absolute_import | ||
|
r15168 | |||
from mercurial.i18n import _ | ||||
|
r30180 | from mercurial import util | ||
|
r15168 | |||
|
r29310 | from . import ( | ||
basestore, | ||||
lfutil, | ||||
) | ||||
|
r15168 | |||
|
r43346 | |||
|
r15168 | class localstore(basestore.basestore): | ||
|
r15317 | '''localstore first attempts to grab files out of the store in the remote | ||
|
r17424 | Mercurial repository. Failing that, it attempts to grab the files from | ||
|
r15317 | the user cache.''' | ||
|
r15168 | |||
def __init__(self, ui, repo, remote): | ||||
|
r17191 | self.remote = remote.local() | ||
|
r18155 | super(localstore, self).__init__(ui, repo, self.remote.url()) | ||
|
r15168 | |||
|
r15317 | def put(self, source, hash): | ||
if lfutil.instore(self.remote, hash): | ||||
return | ||||
|
r19007 | lfutil.link(source, lfutil.storepath(self.remote, hash)) | ||
|
r15168 | |||
|
r17411 | def exists(self, hashes): | ||
retval = {} | ||||
for hash in hashes: | ||||
retval[hash] = lfutil.instore(self.remote, hash) | ||||
return retval | ||||
|
r15168 | def _getfile(self, tmpfile, filename, hash): | ||
|
r19000 | path = lfutil.findfile(self.remote, hash) | ||
if not path: | ||||
|
r43346 | raise basestore.StoreError( | ||
|
r43347 | filename, hash, self.url, _(b"can't get file locally") | ||
|
r43346 | ) | ||
|
r43347 | with open(path, b'rb') as fd: | ||
|
r43346 | return lfutil.copyandhash(util.filechunkiter(fd), tmpfile) | ||
|
r15168 | |||
|
r29067 | def _verifyfiles(self, contents, filestocheck): | ||
failed = False | ||||
for cset, filename, expectedhash in filestocheck: | ||||
|
r29421 | storepath, exists = lfutil.findstorepath(self.repo, expectedhash) | ||
if not exists: | ||||
storepath, exists = lfutil.findstorepath( | ||||
|
r43346 | self.remote, expectedhash | ||
) | ||||
|
r29067 | if not exists: | ||
|
r15168 | self.ui.warn( | ||
|
r43347 | _(b'changeset %s: %s references missing %s\n') | ||
|
r43346 | % (cset, filename, storepath) | ||
) | ||||
|
r29067 | failed = True | ||
elif contents: | ||||
actualhash = lfutil.hashfile(storepath) | ||||
if actualhash != expectedhash: | ||||
self.ui.warn( | ||||
|
r43347 | _(b'changeset %s: %s references corrupted %s\n') | ||
|
r43346 | % (cset, filename, storepath) | ||
) | ||||
|
r29067 | failed = True | ||
return failed | ||||