1 |
commit: c783c57205107bfa75441b90a35f414163baad42 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Sep 12 23:09:56 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Sep 14 06:23:58 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c783c572 |
7 |
|
8 |
egencache: add --external-cache-only option (bug 737470) |
9 |
|
10 |
The --external-cache-only option is useful for client-side |
11 |
use cases where writing cache files inside the repository itself |
12 |
may interfere with repository verification. This option is |
13 |
currently supported for --update and --update-pkg-desc-index |
14 |
actions, for which consumers of the corresponding cache or |
15 |
index files are already capable of consuming files from the |
16 |
external cache directory (/var/cache/edb/dep). |
17 |
|
18 |
Bug: https://bugs.gentoo.org/737470 |
19 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
20 |
|
21 |
bin/egencache | 44 ++++++++++++++++++++++++++------------------ |
22 |
cnf/repo.postsync.d/example | 19 +++++++++---------- |
23 |
man/egencache.1 | 9 ++++++++- |
24 |
3 files changed, 43 insertions(+), 29 deletions(-) |
25 |
|
26 |
diff --git a/bin/egencache b/bin/egencache |
27 |
index 532e37f20..4ee63edad 100755 |
28 |
--- a/bin/egencache |
29 |
+++ b/bin/egencache |
30 |
@@ -107,6 +107,9 @@ def parse_args(args): |
31 |
common.add_argument("--config-root", |
32 |
help="location of portage config files", |
33 |
dest="portage_configroot") |
34 |
+ common.add_argument("--external-cache-only", |
35 |
+ action="store_true", |
36 |
+ help="Output only to the external cache (not the repository itself)") |
37 |
common.add_argument("--gpg-dir", |
38 |
help="override the PORTAGE_GPG_DIR variable", |
39 |
dest="gpg_dir") |
40 |
@@ -246,7 +249,7 @@ def parse_args(args): |
41 |
|
42 |
class GenCache: |
43 |
def __init__(self, portdb, cp_iter=None, max_jobs=None, max_load=None, |
44 |
- rsync=False): |
45 |
+ rsync=False, external_cache_only=False): |
46 |
# The caller must set portdb.porttrees in order to constrain |
47 |
# findname, cp_list, and cpv_list to the desired tree. |
48 |
tree = portdb.porttrees[0] |
49 |
@@ -263,18 +266,21 @@ class GenCache: |
50 |
else: |
51 |
self._cp_set = None |
52 |
self._cp_missing = set() |
53 |
- write_auxdb = "metadata-transfer" in portdb.settings.features |
54 |
+ write_auxdb = external_cache_only or "metadata-transfer" in portdb.settings.features |
55 |
self._regen = MetadataRegen(portdb, cp_iter=cp_iter, |
56 |
consumer=self._metadata_callback, |
57 |
max_jobs=max_jobs, max_load=max_load, |
58 |
write_auxdb=write_auxdb, main=True) |
59 |
self.returncode = os.EX_OK |
60 |
conf = portdb.repositories.get_repo_for_location(tree) |
61 |
- self._trg_caches = tuple(conf.iter_pregenerated_caches( |
62 |
- self._auxdbkeys, force=True, readonly=False)) |
63 |
- if not self._trg_caches: |
64 |
- raise Exception("cache formats '%s' aren't supported" % |
65 |
- (" ".join(conf.cache_formats),)) |
66 |
+ if external_cache_only: |
67 |
+ self._trg_caches = () |
68 |
+ else: |
69 |
+ self._trg_caches = tuple(conf.iter_pregenerated_caches( |
70 |
+ self._auxdbkeys, force=True, readonly=False)) |
71 |
+ if not self._trg_caches: |
72 |
+ raise Exception("cache formats '%s' aren't supported" % |
73 |
+ (" ".join(conf.cache_formats),)) |
74 |
|
75 |
if rsync: |
76 |
for trg_cache in self._trg_caches: |
77 |
@@ -1092,7 +1098,8 @@ def egencache_main(args): |
78 |
gen_cache = GenCache(portdb, cp_iter=cp_iter, |
79 |
max_jobs=options.jobs, |
80 |
max_load=options.load_average, |
81 |
- rsync=options.rsync) |
82 |
+ rsync=options.rsync, |
83 |
+ external_cache_only=options.external_cache_only) |
84 |
gen_cache.run() |
85 |
if options.tolerant: |
86 |
ret.append(os.EX_OK) |
87 |
@@ -1100,20 +1107,21 @@ def egencache_main(args): |
88 |
ret.append(gen_cache.returncode) |
89 |
|
90 |
if options.update_pkg_desc_index: |
91 |
- if repo_config.writable: |
92 |
+ if not options.external_cache_only and repo_config.writable: |
93 |
writable_location = repo_config.location |
94 |
else: |
95 |
writable_location = os.path.join(portdb.depcachedir, |
96 |
repo_config.location.lstrip(os.sep)) |
97 |
- msg = [ |
98 |
- "WARNING: Repository is not writable: %s" % ( |
99 |
- repo_config.location,), |
100 |
- " Using cache directory instead: %s" % ( |
101 |
- writable_location,) |
102 |
- ] |
103 |
- msg = "".join(line + '\n' for line in msg) |
104 |
- writemsg_level(msg, |
105 |
- level=logging.WARNING, noiselevel=-1) |
106 |
+ if not options.external_cache_only: |
107 |
+ msg = [ |
108 |
+ "WARNING: Repository is not writable: %s" % ( |
109 |
+ repo_config.location,), |
110 |
+ " Using cache directory instead: %s" % ( |
111 |
+ writable_location,) |
112 |
+ ] |
113 |
+ msg = "".join(line + '\n' for line in msg) |
114 |
+ writemsg_level(msg, |
115 |
+ level=logging.WARNING, noiselevel=-1) |
116 |
|
117 |
gen_index = GenPkgDescIndex(repo_config, portdb, os.path.join( |
118 |
writable_location, "metadata", "pkg_desc_index"), |
119 |
|
120 |
diff --git a/cnf/repo.postsync.d/example b/cnf/repo.postsync.d/example |
121 |
index d1e385c11..f7c6f5092 100644 |
122 |
--- a/cnf/repo.postsync.d/example |
123 |
+++ b/cnf/repo.postsync.d/example |
124 |
@@ -46,17 +46,16 @@ if [ -n "${repository_name}" ]; then |
125 |
fi |
126 |
fi |
127 |
|
128 |
- # Regenerate the metadata/pkg_desc_index file if needed. It's not |
129 |
+ # Regenerate the metadata/pkg_desc_index file. This is not |
130 |
# needed for https://gitweb.gentoo.org/repo/sync/gentoo.git which |
131 |
- # provides a freshly generated copy. |
132 |
- if [[ ! -e ${repository_path}/metadata/pkg_desc_index || ( |
133 |
- -d ${repository_path}/metadata/md5-cache && |
134 |
- -n $(find "${repository_path}/metadata/md5-cache" -type f -newer "${repository_path}/metadata/pkg_desc_index" -print -quit) ) ]]; then |
135 |
- if ! egencache --update-pkg-desc-index --repo="${repository_name}" ${PORTAGE_VERBOSE+--verbose} |
136 |
- then |
137 |
- echo "!!! egencache failed!" |
138 |
- ret=1 |
139 |
- fi |
140 |
+ # provides a freshly generated copy. The --external-cache-only |
141 |
+ # option causes the metadata/pkg_desc_index file to be written under |
142 |
+ # /var/cache/edb/dep instead of the repository itself, so that it |
143 |
+ # does not interfere with repository verification. |
144 |
+ if ! egencache --update-pkg-desc-index --external-cache-only --repo="${repository_name}" ${PORTAGE_VERBOSE+--verbose} |
145 |
+ then |
146 |
+ echo "!!! egencache failed!" |
147 |
+ ret=1 |
148 |
fi |
149 |
fi |
150 |
|
151 |
|
152 |
diff --git a/man/egencache.1 b/man/egencache.1 |
153 |
index ae7370e21..79c1c3159 100644 |
154 |
--- a/man/egencache.1 |
155 |
+++ b/man/egencache.1 |
156 |
@@ -1,4 +1,4 @@ |
157 |
-.TH "EGENCACHE" "1" "Dec 2015" "Portage VERSION" "Portage" |
158 |
+.TH "EGENCACHE" "1" "Sep 2020" "Portage VERSION" "Portage" |
159 |
.SH "NAME" |
160 |
egencache \- generate metadata cache for ebuild repositories |
161 |
.SH "SYNOPSIS" |
162 |
@@ -55,6 +55,13 @@ Location of portage config files. |
163 |
.br |
164 |
Defaults to /. |
165 |
.TP |
166 |
+.BR "\-\-external\-cache\-only" |
167 |
+Output to the external cache rather than to the repository itself. |
168 |
+This is useful for client\-side usage, where it may not be possible to |
169 |
+output to the repository itself since that would interfere with |
170 |
+repository verification. This option is supported by the \-\-update and |
171 |
+\-\-update\-pkg\-desc\-index actions. |
172 |
+.TP |
173 |
.BR "\-\-gpg\-dir" |
174 |
Override the PORTAGE_GPG_DIR variable. |
175 |
.TP |