1 |
commit: 26d038ae9c2f499cfb52486913cc326854a50571 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Mar 27 17:07:57 2016 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Mar 27 17:07:57 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=26d038ae |
7 |
|
8 |
q: migrate to new repo posthook system |
9 |
|
10 |
This also extends the reinit interface to optionally take a path to the |
11 |
overlay to process. That allows the postsync hook to fire on specific |
12 |
repos rather than all of them. |
13 |
|
14 |
URL: https://bugs.gentoo.org/522032 |
15 |
|
16 |
Makefile | 7 ++++++- |
17 |
Makefile.am | 5 +++++ |
18 |
main.c | 3 ++- |
19 |
main.h | 1 + |
20 |
man/q.1 | 6 +++--- |
21 |
q.c | 34 +++++++++++++++++++++++++++------- |
22 |
repo.postsync/q-reinit | 10 ++++++++++ |
23 |
7 files changed, 54 insertions(+), 12 deletions(-) |
24 |
|
25 |
diff --git a/Makefile b/Makefile |
26 |
index fe6092f..baa27c2 100644 |
27 |
--- a/Makefile |
28 |
+++ b/Makefile |
29 |
@@ -27,9 +27,11 @@ LIBADD += $(shell echo | $(CC) -dM -E - | grep -q ' __FreeBSD__' && echo '-lk |
30 |
LIBADD += -liniparser |
31 |
DESTDIR := |
32 |
PREFIX := $(DESTDIR)/usr |
33 |
+ETCDIR := $(DESTDIR)/etc |
34 |
STRIP := strip |
35 |
MKDIR := mkdir -p |
36 |
CP := cp |
37 |
+INSTALL_EXE := install -m755 |
38 |
|
39 |
ifndef V |
40 |
Q = @ |
41 |
@@ -106,13 +108,16 @@ testclean: |
42 |
|
43 |
install: all |
44 |
$(MKDIR) $(PREFIX)/bin/ |
45 |
- $(CP) q $(PREFIX)/bin/ |
46 |
+ $(INSTALL_EXE) q $(PREFIX)/bin/ |
47 |
|
48 |
set -e ; \ |
49 |
for applet in $(filter-out q,$(APPLETS)) ; do \ |
50 |
ln -sf q $(PREFIX)/bin/$${applet} ; \ |
51 |
done |
52 |
|
53 |
+ $(MKDIR) $(ETCDIR)/portage/repo.postsync.d |
54 |
+ $(INSTALL_EXE) repo.postsync/* $(ETCDIR)/portage/repo.postsync.d/ |
55 |
+ |
56 |
ifneq ($(wildcard man/*.1),) |
57 |
$(MKDIR) $(PREFIX)/share/man/man1/ |
58 |
cp $(wildcard man/*.1) $(PREFIX)/share/man/man1/ |
59 |
|
60 |
diff --git a/Makefile.am b/Makefile.am |
61 |
index 225c979..362ee21 100644 |
62 |
--- a/Makefile.am |
63 |
+++ b/Makefile.am |
64 |
@@ -2,6 +2,11 @@ ACLOCAL_AMFLAGS = -I autotools/m4 |
65 |
|
66 |
SUBDIRS = autotools/gnulib |
67 |
|
68 |
+portagedir = $(sysconfdir)/portage |
69 |
+postsyncddir = $(portagedir)/repo.postsync.d |
70 |
+ |
71 |
+dist_postsyncd_SCRIPTS = repo.postsync/q-reinit |
72 |
+ |
73 |
bin_PROGRAMS = q |
74 |
q_SOURCES = main.c |
75 |
q_CPPFLAGS = \ |
76 |
|
77 |
diff --git a/main.c b/main.c |
78 |
index e9bacda..0834756 100644 |
79 |
--- a/main.c |
80 |
+++ b/main.c |
81 |
@@ -976,7 +976,8 @@ initialize_flat(const char *overlay, int cache_type, bool force) |
82 |
} |
83 |
|
84 |
if (!quiet) |
85 |
- warn("Updating ebuild %scache ... ", cache_type == CACHE_EBUILD ? "" : "meta"); |
86 |
+ warn("Updating ebuild %scache in %s ... ", |
87 |
+ cache_type == CACHE_EBUILD ? "" : "meta", overlay); |
88 |
|
89 |
count = frac = secs = 0; |
90 |
|
91 |
|
92 |
diff --git a/main.h b/main.h |
93 |
index 877c1ec..6848a9f 100644 |
94 |
--- a/main.h |
95 |
+++ b/main.h |
96 |
@@ -99,3 +99,4 @@ |
97 |
getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL) |
98 |
|
99 |
#define a_argument required_argument |
100 |
+#define opt_argument optional_argument |
101 |
|
102 |
diff --git a/man/q.1 b/man/q.1 |
103 |
index 322e1af..0f8f367 100644 |
104 |
--- a/man/q.1 |
105 |
+++ b/man/q.1 |
106 |
@@ -1,4 +1,4 @@ |
107 |
-.TH q "1" "Mar 2014" "Gentoo Foundation" "q" |
108 |
+.TH q "1" "Mar 2016" "Gentoo Foundation" "q" |
109 |
.SH NAME |
110 |
q \- invoke a portage utility applet |
111 |
.SH SYNOPSIS |
112 |
@@ -11,10 +11,10 @@ q \- invoke a portage utility applet |
113 |
\fB\-i\fR, \fB\-\-install\fR |
114 |
Install symlinks for applets |
115 |
.TP |
116 |
-\fB\-r\fR, \fB\-\-reinitialize\fR |
117 |
+\fB\-r\fR \fI[arg]\fR, \fB\-\-reinitialize\fR \fI[arg]\fR |
118 |
Reinitialize ebuild cache |
119 |
.TP |
120 |
-\fB\-m\fR, \fB\-\-metacache\fR |
121 |
+\fB\-m\fR \fI[arg]\fR, \fB\-\-metacache\fR \fI[arg]\fR |
122 |
Reinitialize metadata cache |
123 |
.TP |
124 |
\fB\-M\fR \fI<arg>\fR, \fB\-\-modpath\fR \fI<arg>\fR |
125 |
|
126 |
diff --git a/q.c b/q.c |
127 |
index 53b359f..1475f99 100644 |
128 |
--- a/q.c |
129 |
+++ b/q.c |
130 |
@@ -8,10 +8,10 @@ |
131 |
|
132 |
#define Q_FLAGS "irmM:" COMMON_FLAGS |
133 |
static struct option const q_long_opts[] = { |
134 |
- {"install", no_argument, NULL, 'i'}, |
135 |
- {"reinitialize", no_argument, NULL, 'r'}, |
136 |
- {"metacache", no_argument, NULL, 'm'}, |
137 |
- {"modpath", a_argument, NULL, 'M'}, |
138 |
+ {"install", no_argument, NULL, 'i'}, |
139 |
+ {"reinitialize", opt_argument, NULL, 'r'}, |
140 |
+ {"metacache", opt_argument, NULL, 'm'}, |
141 |
+ {"modpath", a_argument, NULL, 'M'}, |
142 |
COMMON_LONG_OPTS |
143 |
}; |
144 |
static const char * const q_opts_help[] = { |
145 |
@@ -84,8 +84,24 @@ int q_main(int argc, char **argv) |
146 |
switch (i) { |
147 |
COMMON_GETOPTS_CASES(q) |
148 |
case 'M': modpath = optarg; break; |
149 |
- case 'm': reinitialize_metacache = 1; break; |
150 |
- case 'r': reinitialize = 1; break; |
151 |
+ case 'm': |
152 |
+ if (optarg) { |
153 |
+ const char *path = initialize_flat(optarg, CACHE_METADATA, true); |
154 |
+ if (path) { /* silence warning */ } |
155 |
+ IF_DEBUG(free((void *)path)); |
156 |
+ reinitialize_metacache = -1; |
157 |
+ } else |
158 |
+ reinitialize_metacache = 1; |
159 |
+ break; |
160 |
+ case 'r': |
161 |
+ if (optarg) { |
162 |
+ const char *path = initialize_flat(optarg, CACHE_EBUILD, true); |
163 |
+ if (path) { /* silence warning */ } |
164 |
+ IF_DEBUG(free((void *)path)); |
165 |
+ reinitialize = -1; |
166 |
+ } else |
167 |
+ reinitialize = 1; |
168 |
+ break; |
169 |
case 'i': install = 1; break; |
170 |
} |
171 |
} |
172 |
@@ -128,8 +144,12 @@ int q_main(int argc, char **argv) |
173 |
return ret; |
174 |
} |
175 |
|
176 |
- if (reinitialize || reinitialize_metacache) |
177 |
+ if (reinitialize > 0 || reinitialize_metacache > 0) |
178 |
return 0; |
179 |
+ if (reinitialize < 0 || reinitialize_metacache < 0) { |
180 |
+ reinitialize = reinitialize_metacache = 0; |
181 |
+ return 0; |
182 |
+ } |
183 |
if (argc == optind) |
184 |
q_usage(EXIT_FAILURE); |
185 |
if ((func = lookup_applet(argv[optind])) == NULL) |
186 |
|
187 |
diff --git a/repo.postsync/q-reinit b/repo.postsync/q-reinit |
188 |
new file mode 100644 |
189 |
index 0000000..0833c66 |
190 |
--- /dev/null |
191 |
+++ b/repo.postsync/q-reinit |
192 |
@@ -0,0 +1,10 @@ |
193 |
+#!/bin/sh |
194 |
+ |
195 |
+repository_name=$1 |
196 |
+repository_path=$3 |
197 |
+ |
198 |
+if [ -n "${repository_name}" ]; then |
199 |
+ q ${PORTAGE_QUIET:+-q} --reinitialize="${repository_path}" |
200 |
+fi |
201 |
+ |
202 |
+: |