1 |
commit: 5ac2a8f08101501d0416ad9d79e277c363cea85e |
2 |
Author: Kenneth Raplee <kenrap <AT> kennethraplee <DOT> com> |
3 |
AuthorDate: Sat Apr 2 01:29:10 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Apr 4 19:04:43 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=5ac2a8f0 |
7 |
|
8 |
Enhance the update hash methods for simplification |
9 |
|
10 |
Signed-off-by: Kenneth Raplee <kenrap <AT> kennethraplee.com> |
11 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
12 |
|
13 |
lib/portage/manifest.py | 85 +++++++++++++++++++++++++++---------------------- |
14 |
1 file changed, 47 insertions(+), 38 deletions(-) |
15 |
|
16 |
diff --git a/lib/portage/manifest.py b/lib/portage/manifest.py |
17 |
index 4dca536e4..655eabf68 100644 |
18 |
--- a/lib/portage/manifest.py |
19 |
+++ b/lib/portage/manifest.py |
20 |
@@ -718,63 +718,72 @@ class Manifest: |
21 |
total_bytes = sum(int(self.fhashdict["DIST"][f]["size"]) for f in fetchlist) |
22 |
return total_bytes |
23 |
|
24 |
- def updateFileHashes( |
25 |
- self, ftype, fname, checkExisting=True, ignoreMissing=True, reuseExisting=False |
26 |
+ def updateAllFileHashes( |
27 |
+ self, ftype, fnames, checkExisting=True, ignoreMissing=True, reuseExisting=False |
28 |
): |
29 |
- """Regenerate hashes for the given file""" |
30 |
- if checkExisting: |
31 |
- self.checkFileHashes(ftype, fname, ignoreMissing=ignoreMissing) |
32 |
- if not ignoreMissing and fname not in self.fhashdict[ftype]: |
33 |
- raise FileNotInManifestException(fname) |
34 |
- if fname not in self.fhashdict[ftype]: |
35 |
- self.fhashdict[ftype][fname] = {} |
36 |
- myhashkeys = list(self.hashes) |
37 |
- if reuseExisting: |
38 |
- for k in [h for h in self.fhashdict[ftype][fname] if h in myhashkeys]: |
39 |
- myhashkeys.remove(k) |
40 |
- myhashes = perform_multiple_checksums( |
41 |
- self._getAbsname(ftype, fname), myhashkeys |
42 |
- ) |
43 |
- self.fhashdict[ftype][fname].update(myhashes) |
44 |
+ """Regenerate hashes from a list of files""" |
45 |
+ for fname in fnames: |
46 |
+ if checkExisting: |
47 |
+ self.checkFileHashes(ftype, fname, ignoreMissing=ignoreMissing) |
48 |
+ if not ignoreMissing and fname not in self.fhashdict[ftype]: |
49 |
+ raise FileNotInManifestException(fname) |
50 |
+ if fname not in self.fhashdict[ftype]: |
51 |
+ self.fhashdict[ftype][fname] = {} |
52 |
+ myhashkeys = self.hashes |
53 |
+ if reuseExisting: |
54 |
+ myhashkeys = myhashkeys.difference(self.fhashdict[ftype][fname]) |
55 |
+ myhashes = perform_multiple_checksums( |
56 |
+ self._getAbsname(ftype, fname), myhashkeys |
57 |
+ ) |
58 |
+ self.fhashdict[ftype][fname].update(myhashes) |
59 |
|
60 |
- def updateTypeHashes(self, idtype, checkExisting=False, ignoreMissingFiles=True): |
61 |
- """Regenerate all hashes for all files of the given type""" |
62 |
- for fname in self.fhashdict[idtype]: |
63 |
- self.updateFileHashes(idtype, fname, checkExisting) |
64 |
+ def updateAllTypeHashes( |
65 |
+ self, idtypes, checkExisting=False, ignoreMissingFiles=True |
66 |
+ ): |
67 |
+ """Regenerate all hashes for all files from a list of types""" |
68 |
+ for idtype in idtypes: |
69 |
+ self.updateAllFileHashes( |
70 |
+ ftype=idtype, fnames=self.fhashdict[idtype], checkExisting=checkExisting |
71 |
+ ) |
72 |
|
73 |
def updateAllHashes(self, checkExisting=False, ignoreMissingFiles=True): |
74 |
"""Regenerate all hashes for all files in this Manifest.""" |
75 |
- for idtype in MANIFEST2_IDENTIFIERS: |
76 |
- self.updateTypeHashes( |
77 |
- idtype, |
78 |
- checkExisting=checkExisting, |
79 |
- ignoreMissingFiles=ignoreMissingFiles, |
80 |
- ) |
81 |
+ self.updateTypeHashes( |
82 |
+ idtypes=MANIFEST2_IDENTIFIERS, |
83 |
+ checkExisting=checkExisting, |
84 |
+ ignoreMissingFiles=ignoreMissingFiles, |
85 |
+ ) |
86 |
|
87 |
def updateCpvHashes(self, cpv, ignoreMissingFiles=True): |
88 |
"""Regenerate all hashes associated to the given cpv (includes all AUX and MISC |
89 |
files).""" |
90 |
- self.updateTypeHashes("AUX", ignoreMissingFiles=ignoreMissingFiles) |
91 |
- self.updateTypeHashes("MISC", ignoreMissingFiles=ignoreMissingFiles) |
92 |
- ebuildname = "%s.ebuild" % self._catsplit(cpv)[1] |
93 |
- self.updateFileHashes( |
94 |
- "EBUILD", ebuildname, ignoreMissingFiles=ignoreMissingFiles |
95 |
+ self.updateAllTypeHashes( |
96 |
+ idtypes=("AUX", "MISC"), |
97 |
+ ignoreMissingFiles=ignoreMissingFiles, |
98 |
+ ) |
99 |
+ self.updateAllFileHashes( |
100 |
+ ftype="EBUILD", |
101 |
+ fnames=(f"{self._catsplit(cpv)[1]}.ebuild",), |
102 |
+ ignoreMissingFiles=ignoreMissingFiles, |
103 |
+ ) |
104 |
+ self.updateAllFileHashes( |
105 |
+ ftype="DIST", |
106 |
+ fnames=self._getCpvDistfiles(cpv), |
107 |
+ ignoreMissingFiles=ignoreMissingFiles, |
108 |
) |
109 |
- for f in self._getCpvDistfiles(cpv): |
110 |
- self.updateFileHashes("DIST", f, ignoreMissingFiles=ignoreMissingFiles) |
111 |
|
112 |
def updateHashesGuessType(self, fname, *args, **kwargs): |
113 |
"""Regenerate hashes for the given file (guesses the type and then |
114 |
calls updateFileHashes).""" |
115 |
mytype = self.guessType(fname) |
116 |
- if mytype == "AUX": |
117 |
- fname = fname[len("files" + os.sep) :] |
118 |
- elif mytype is None: |
119 |
+ if mytype is None: |
120 |
return |
121 |
+ elif mytype == "AUX": |
122 |
+ fname = fname[len(f"files{os.sep}") :] |
123 |
myrealtype = self.findFile(fname) |
124 |
if myrealtype is not None: |
125 |
mytype = myrealtype |
126 |
- return self.updateFileHashes(mytype, fname, *args, **kwargs) |
127 |
+ return self.updateAllFileHashes(ftype=mytype, fnames=(fname,), *args, **kwargs) |
128 |
|
129 |
def getFileData(self, ftype, fname, key): |
130 |
"""Return the value of a specific (type,filename,key) triple, mainly useful |