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'''
|
2016-05-10 15:20:51 +03:00
|
|
|
from __future__ import absolute_import
|
2011-09-24 19:35:45 +04:00
|
|
|
|
|
|
|
from mercurial.i18n import _
|
2016-10-12 13:22:18 +03:00
|
|
|
from mercurial import util
|
2011-09-24 19:35:45 +04:00
|
|
|
|
2016-05-10 15:20:51 +03:00
|
|
|
from . import (
|
|
|
|
basestore,
|
|
|
|
lfutil,
|
|
|
|
)
|
2011-09-24 19:35:45 +04:00
|
|
|
|
|
|
|
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:
|
2016-10-12 13:22:18 +03:00
|
|
|
return lfutil.copyandhash(
|
|
|
|
util.filechunkiter(fd), tmpfile)
|
2011-09-24 19:35:45 +04:00
|
|
|
|
2016-05-04 00:31:32 +03:00
|
|
|
def _verifyfiles(self, contents, filestocheck):
|
|
|
|
failed = False
|
|
|
|
for cset, filename, expectedhash in filestocheck:
|
2016-06-23 23:37:17 +03:00
|
|
|
storepath, exists = lfutil.findstorepath(self.repo, expectedhash)
|
|
|
|
if not exists:
|
|
|
|
storepath, exists = lfutil.findstorepath(
|
|
|
|
self.remote, expectedhash)
|
2016-05-04 00:31:32 +03:00
|
|
|
if not exists:
|
2011-09-24 19:35:45 +04:00
|
|
|
self.ui.warn(
|
2016-05-04 00:31:32 +03:00
|
|
|
_('changeset %s: %s references missing %s\n')
|
2013-02-04 05:46:53 +04:00
|
|
|
% (cset, filename, storepath))
|
2016-05-04 00:31:32 +03:00
|
|
|
failed = True
|
|
|
|
elif contents:
|
|
|
|
actualhash = lfutil.hashfile(storepath)
|
|
|
|
if actualhash != expectedhash:
|
|
|
|
self.ui.warn(
|
|
|
|
_('changeset %s: %s references corrupted %s\n')
|
|
|
|
% (cset, filename, storepath))
|
|
|
|
failed = True
|
|
|
|
return failed
|