2011-09-24 19:35:45 +04:00
|
|
|
# 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.
|
|
|
|
|
2011-10-13 04:59:27 +04:00
|
|
|
'''store class for local filesystem'''
|
2011-09-24 19:35:45 +04:00
|
|
|
|
|
|
|
from mercurial.i18n import _
|
|
|
|
|
|
|
|
import lfutil
|
|
|
|
import basestore
|
|
|
|
|
|
|
|
class localstore(basestore.basestore):
|
2011-10-20 21:24:11 +04:00
|
|
|
'''localstore first attempts to grab files out of the store in the remote
|
2012-08-16 00:38:42 +04:00
|
|
|
Mercurial repository. Failing that, it attempts to grab the files from
|
2011-10-20 21:24:11 +04:00
|
|
|
the user cache.'''
|
2011-09-24 19:35:45 +04:00
|
|
|
|
|
|
|
def __init__(self, ui, repo, remote):
|
2012-07-13 23:46:53 +04:00
|
|
|
self.remote = remote.local()
|
2012-12-13 22:19:06 +04:00
|
|
|
super(localstore, self).__init__(ui, repo, self.remote.url())
|
2011-09-24 19:35:45 +04:00
|
|
|
|
2011-10-20 21:24:11 +04:00
|
|
|
def put(self, source, hash):
|
|
|
|
if lfutil.instore(self.remote, hash):
|
|
|
|
return
|
2013-04-16 01:34:36 +04:00
|
|
|
lfutil.link(source, lfutil.storepath(self.remote, hash))
|
2011-09-24 19:35:45 +04:00
|
|
|
|
2012-08-15 06:38:25 +04:00
|
|
|
def exists(self, hashes):
|
|
|
|
retval = {}
|
|
|
|
for hash in hashes:
|
|
|
|
retval[hash] = lfutil.instore(self.remote, hash)
|
|
|
|
return retval
|
|
|
|
|
2011-09-24 19:35:45 +04:00
|
|
|
|
|
|
|
def _getfile(self, tmpfile, filename, hash):
|
2013-04-16 01:35:43 +04:00
|
|
|
path = lfutil.findfile(self.remote, hash)
|
|
|
|
if not path:
|
2012-12-13 22:19:06 +04:00
|
|
|
raise basestore.StoreError(filename, hash, self.url,
|
2012-06-12 16:18:18 +04:00
|
|
|
_("can't get file locally"))
|
2016-01-13 01:27:42 +03:00
|
|
|
with open(path, 'rb') as fd:
|
2011-10-20 21:24:11 +04:00
|
|
|
return lfutil.copyandhash(fd, tmpfile)
|
2011-09-24 19:35:45 +04:00
|
|
|
|
|
|
|
def _verifyfile(self, cctx, cset, contents, standin, verified):
|
|
|
|
filename = lfutil.splitstandin(standin)
|
|
|
|
if not filename:
|
|
|
|
return False
|
|
|
|
fctx = cctx[standin]
|
|
|
|
key = (filename, fctx.filenode())
|
|
|
|
if key in verified:
|
|
|
|
return False
|
|
|
|
|
|
|
|
expecthash = fctx.data()[0:40]
|
2015-04-05 02:34:36 +03:00
|
|
|
storepath, exists = lfutil.findstorepath(self.remote, expecthash)
|
2011-09-24 19:35:45 +04:00
|
|
|
verified.add(key)
|
2015-04-05 02:34:36 +03:00
|
|
|
if not exists:
|
2011-09-24 19:35:45 +04:00
|
|
|
self.ui.warn(
|
2013-02-04 05:46:53 +04:00
|
|
|
_('changeset %s: %s references missing %s\n')
|
|
|
|
% (cset, filename, storepath))
|
2011-09-24 19:35:45 +04:00
|
|
|
return True # failed
|
|
|
|
|
|
|
|
if contents:
|
|
|
|
actualhash = lfutil.hashfile(storepath)
|
|
|
|
if actualhash != expecthash:
|
|
|
|
self.ui.warn(
|
2013-02-04 05:46:53 +04:00
|
|
|
_('changeset %s: %s references corrupted %s\n')
|
|
|
|
% (cset, filename, storepath))
|
2011-09-24 19:35:45 +04:00
|
|
|
return True # failed
|
|
|
|
return False
|