Debian Codegraph @

hgext/largefiles/localstore.py

raw
1 # Copyright 2009-2010 Gregory P. Ward
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated
3 # Copyright 2010-2011 Fog Creek Software
4 # Copyright 2010-2011 Unity Technologies
5 #
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
8
9 '''store class for local filesystem'''
10
11 from __future__ import annotations
12
13 from mercurial.i18n import _
14 from mercurial import util
15
16 from . import (
17 basestore,
18 lfutil,
19 )
20
21
22 class localstore(basestore.basestore):
23 """localstore first attempts to grab files out of the store in the remote
24 Mercurial repository. Failing that, it attempts to grab the files from
25 the user cache."""
26
27 def __init__(self, ui, repo, remote):
28 self.remote = remote.local()
29 super().__init__(ui, repo, self.remote.url())
30
31 def put(self, source, hash):
32 if lfutil.instore(self.remote, hash):
33 return
34 lfutil.link(source, lfutil.storepath(self.remote, hash))
35
36 def exists(self, hashes):
37 retval = {}
38 for hash in hashes:
39 retval[hash] = lfutil.instore(self.remote, hash)
40 return retval
41
42 def _getfile(self, tmpfile, filename, hash):
43 path = lfutil.findfile(self.remote, hash)
44 if not path:
45 raise basestore.StoreError(
46 filename, hash, self.url, _(b"can't get file locally")
47 )
48 with open(path, 'rb') as fd:
49 return lfutil.copyandhash(util.filechunkiter(fd), tmpfile)
50
51 def _verifyfiles(self, contents, filestocheck):
52 failed = False
53 for cset, filename, expectedhash in filestocheck:
54 storepath, exists = lfutil.findstorepath(self.repo, expectedhash)
55 if not exists:
56 storepath, exists = lfutil.findstorepath(
57 self.remote, expectedhash
58 )
59 if not exists:
60 self.ui.warn(
61 _(b'changeset %s: %s references missing %s\n')
62 % (cset, filename, storepath)
63 )
64 failed = True
65 elif contents:
66 actualhash = lfutil.hashfile(storepath)
67 if actualhash != expectedhash:
68 self.ui.warn(
69 _(b'changeset %s: %s references corrupted %s\n')
70 % (cset, filename, storepath)
71 )
72 failed = True
73 return failed