]> git.pld-linux.org Git - packages/poldek.git/blame - poldek-caplookup.patch
- updated to 0.18.8, release 2 for Ra
[packages/poldek.git] / poldek-caplookup.patch
CommitLineData
ccd49585
MM
1Index: main.c
2===================================================================
3RCS file: /cvsroot/installer/poldek/main.c,v
4retrieving revision 1.110.4.14
5retrieving revision 1.110.4.15
6diff -u -r1.110.4.14 -r1.110.4.15
7--- main.c 6 Jun 2004 20:47:51 -0000 1.110.4.14
8+++ main.c 2 Jul 2004 17:42:39 -0000 1.110.4.15
9@@ -11,7 +11,7 @@
10 */
11
12 /*
13- $Id$
14+ $Id$
15 */
16
17 #ifdef HAVE_CONFIG_H
18@@ -223,8 +223,10 @@
19 #define OPT_INST_DOWNGRADE 1058
20 #define OPT_INST_UNIQNAMES 'Q'
21
22-#define OPT_RPMONLY_FORCE 1059
23-#define OPT_RPMONLY_NODEPS 1060
24+#define OPT_CAPLOOKUP 1059
25+#define OPT_RPMONLY_FORCE 1070
26+#define OPT_RPMONLY_NODEPS 1071
27+
28
29 #define OPT_UNINSTALL 'e'
30
31@@ -327,6 +329,9 @@
32 {0,0,0,0, N_("Packages spec:"), 65},
33 {"pset", OPT_PKGSET, "FILE", 0, N_("Take package set definition from FILE"), 65 },
34 {"pkgset", 0, 0, OPTION_ALIAS | OPTION_HIDDEN, 0, 65 }, /* backward compat */
35+{"caplookup", OPT_CAPLOOKUP, 0, 0,
36+ N_("Look into package capabilities & files to resolve packages"), 65 },
37+
38
39 // obsoleted by '#'
40 {"nevr", OPT_NEVR, "\"NAME [[E:][V[-R]]]\"", OPTION_HIDDEN,
41@@ -385,7 +390,7 @@
42
43 {"nodeps", OPT_INST_NODEPS, 0, 0,
44 N_("Install packages with broken dependencies"), 71 },
45-
46+
47 {"force", OPT_INST_FORCE, 0, 0,
48 N_("Be unconcerned"), 71 },
49
50@@ -560,6 +565,10 @@
51 case OPT_PKGSET:
52 n_array_push(argsp->pkgdef_sets, arg);
53 break;
54+
55+ case OPT_CAPLOOKUP:
56+ argsp->inst.flags |= INSTS_CAPLOOKUP;
57+ break;
58
59 case 'l':
60 if (argsp->mjrmode != MODE_SRCLIST)
61Index: pkgset-install.c
62===================================================================
63RCS file: /cvsroot/installer/poldek/pkgset-install.c,v
64retrieving revision 1.82.4.10
65retrieving revision 1.82.4.11
66diff -u -r1.82.4.10 -r1.82.4.11
67--- pkgset-install.c 22 Jun 2004 17:13:35 -0000 1.82.4.10
68+++ pkgset-install.c 2 Jul 2004 17:42:39 -0000 1.82.4.11
69@@ -11,7 +11,7 @@
70 */
71
72 /*
73- $Id$
74+ $Id$
75 */
76
77 #ifdef HAVE_CONFIG_H
78@@ -171,9 +171,11 @@
79 logn(LOGERR, msg, pkg_snprintf_s(pkg), eqs, giveup);
80 install = -1;
81
82- } else if (is_hand_marked && !freshen) { /* msg without "freshen" */
83- msgn(0, msg, pkg_snprintf_s(pkg), eqs, skiped);
84-
85+ } else if (is_hand_marked) {
86+ int vl = 0;
87+ if (freshen)
bb9488c1 88+ vl = 3;
ccd49585
MM
89+ msgn(vl, msg, pkg_snprintf_s(pkg), eqs, skiped);
90 }
91 }
92 }
93@@ -2331,11 +2333,10 @@
94 }
95 }
96
97-static
98-int unmark_name_dups(tn_array *pkgs)
99+static int unmark_name_dups(tn_array *pkgs)
100 {
101 struct pkg *pkg, *pkg2;
102- int i, n;
103+ int i, n, nmarked;
104
105 if (n_array_size(pkgs) < 2)
106 return 0;
107@@ -2349,7 +2350,8 @@
108
109 if (!pkg_is_marked(pkg))
110 continue;
111-
112+
113+ nmarked++;
114 DBGF("%s\n", pkg_snprintf_s(pkg));
115
116
117@@ -2360,6 +2362,7 @@
118
119 i++;
120 n++;
a129eb45 121+ //nmarked--;
ccd49585
MM
122 if (i == n_array_size(pkgs))
123 break;
124 pkg2 = n_array_nth(pkgs, i);
125@@ -2367,9 +2370,100 @@
126 }
127 }
128
129- return n;
130+ return nmarked;
131+}
132+
133+static
134+int prepare_icap(struct upgrade_s *upg, const char *capname, tn_array *pkgs)
135+{
136+ int i, found = 0;
137+ tn_array *dbpkgs;
138+ struct capreq *cap = capreq_new_name_a(capname);
139+
140+ dbpkgs = rpm_get_provides_dbpkgs(upg->inst->db->dbh, cap, NULL, 0);
141+ if (dbpkgs == NULL) {
142+ struct pkg *pkg;
143+ if (upg->inst->flags & INSTS_FRESHEN)
144+ return 0;
145+
146+ pkg = n_array_nth(pkgs, 0);
147+ pkg_hand_mark(pkg);
148+ return 1;
149+ }
150+
151+ n_array_sort_ex(pkgs, (tn_fn_cmp)pkg_cmp_name_evr_rev);
152+
153+ for (i=0; i < n_array_size(dbpkgs); i++) {
154+ struct dbpkg *dbpkg = n_array_nth(dbpkgs, i);
155+ int n = n_array_bsearch_idx_ex(pkgs, dbpkg->pkg,
156+ (tn_fn_cmp)pkg_cmp_name);
157+
158+ DBGF("%s: %s\n", capname, pkg_snprintf_s0(dbpkg->pkg));
159+
160+ if (n < 0)
161+ continue;
162+
163+ for (; n < n_array_size(pkgs); n++) {
164+ struct pkg *pkg = n_array_nth(pkgs, n);
165+ int cmprc, mark = 0;
166+
167+ DBGF("%s: %s cmp %s\n", capname, pkg_snprintf_s(pkg),
168+ pkg_snprintf_s0(dbpkg->pkg));
169+ if (pkg_cmp_name(pkg, dbpkg->pkg) != 0)
170+ break;
171+
172+ cmprc = pkg_cmp_name_evr(pkg, dbpkg->pkg);
173+ if (cmprc > 0)
174+ mark = 1;
175+
176+ else if (cmprc == 0 && upg->inst->flags & INSTS_REINSTALL)
177+ mark = 1;
178+
179+ else if (cmprc < 0 && upg->inst->flags & INSTS_DOWNGRADE)
180+ mark = 1;
181+
182+ if (mark) {
183+ found = 1;
184+ msgn(1, "%s: marked as %s provider", pkg_snprintf_s(pkg),
185+ capname);
186+
187+ pkg_hand_mark(pkg);
188+ goto l_end;
189+
190+ } else if (cmprc <= 0) {
191+ char *eqs = cmprc == 0 ? "equal" : "newer";
192+ msgn(1, "%s: %s version of %s is installed (%s), skipped",
193+ capname, eqs, pkg_snprintf_s0(dbpkg->pkg),
194+ pkg_snprintf_s(pkg));
195+
196+ } else {
197+ n_assert(0);
198+
199+ }
200+ }
201+ }
202+l_end:
203+ if (dbpkgs)
204+ n_array_free(dbpkgs);
205+
206+ return found;
207 }
208
209+static
210+int prepare_icaps(struct upgrade_s *upg)
211+{
212+ tn_array *keys;
213+ int i;
214+
215+ keys = n_hash_keys_cp(upg->inst->icaps);
216+ for (i=0; i < n_array_size(keys); i++) {
217+ const char *cap = n_array_nth(keys, i);
218+ tn_array *pkgs = n_hash_get(upg->inst->icaps, cap);
219+ prepare_icap(upg, cap, pkgs);
220+ }
221+ n_array_free(keys);
222+ return 1;
223+}
224
225 int pkgset_install(struct pkgset *ps, struct inst_s *inst,
226 struct install_info *iinf)
227@@ -2381,13 +2475,15 @@
228 if (inst->flags & INSTS_INSTALL)
229 n_assert((inst->flags & INSTS_UPGRADE) == 0);
230
231-
232 packages_mark(ps->pkgs, 0, PKG_INTERNALMARK | PKG_INDIRMARK);
233
234- unmark_name_dups(ps->pkgs);
235-
236- mem_info(1, "ENTER pkgset_install:");
237+ mem_info(2, "ENTER pkgset_install:");
238 init_upgrade_s(&upg, ps, inst);
239+ prepare_icaps(&upg);
240+ if (unmark_name_dups(ps->pkgs) == 0) {
241+ msgn(1, _("Nothing to do"));
242+ return 1;
243+ }
244
245 is_particle = inst->flags & INSTS_PARTICLE;
246
247@@ -2421,8 +2517,11 @@
248 }
249 }
250
251- if (nmarked == 0)
252+ if (nmarked == 0) {
253+ msgn(1, _("Nothing to do"));
254 goto l_end;
255+ }
256+
257
258 if (nmarked == 1)
259 inst->flags &= ~INSTS_PARTICLE;
260Index: pkgset.c
261===================================================================
262RCS file: /cvsroot/installer/poldek/pkgset.c,v
263retrieving revision 1.55.4.3
264retrieving revision 1.55.4.4
265diff -u -r1.55.4.3 -r1.55.4.4
266--- pkgset.c 6 Jun 2004 20:47:51 -0000 1.55.4.3
267+++ pkgset.c 2 Jul 2004 17:42:40 -0000 1.55.4.4
268@@ -11,7 +11,7 @@
269 */
270
271 /*
272- $Id$
273+ $Id$
274 */
275
276 #include <limits.h>
277@@ -150,6 +150,7 @@
278 inst->rpmopts = n_array_new(4, free, (tn_fn_cmp)strcmp);
279 inst->hold_patterns = n_array_new(4, free, (tn_fn_cmp)strcmp);
280 inst->ign_patterns = n_array_new(4, free, (tn_fn_cmp)strcmp);
281+ inst->icaps = n_hash_new(21, (tn_fn_free)n_array_free);
282 }
283
284 struct pkgset *pkgset_new(unsigned optflags)
285@@ -836,9 +837,40 @@
286 return rc;
287 }
288
289+static int pkgset_mark_bycap(struct pkgset *ps, struct inst_s *inst,
290+ const struct pkgdef *pdef)
291+{
292+ tn_array *pkgs;
293+
294+ n_assert(inst->flags & INSTS_CAPLOOKUP);
295+
296+ pkgs = pkgset_lookup_cap(ps, pdef->pkg->name);
297+ if (pkgs == NULL || n_array_size(pkgs) == 0) {
298+ logn(LOGERR, _("mark: %s not found"), pdef->pkg->name);
299+ if (pkgs)
300+ n_array_free(pkgs);
301+ return 0;
302+ }
303+
304+ if (verbose > 1) {
305+ int i;
306+
307+ msgn(2, "%s: %d package(s) found:", pdef->pkg->name,
308+ n_array_size(pkgs));
309+ for (i=0; i<n_array_size(pkgs); i++)
310+ msgn(2, " - %s", pkg_snprintf_s(n_array_nth(pkgs, i)));
311+
312+ }
313+
314+ n_hash_insert(inst->icaps, pdef->pkg->name, pkgs);
315+ return n_array_size(pkgs);
316+}
317+
318+
319+
320 static
321-int pkgset_mark_pkgdef_exact(struct pkgset *ps, const struct pkgdef *pdef,
322- int nodeps)
323+int pkgset_mark_pkgdef_exact(struct pkgset *ps, struct inst_s *inst,
324+ const struct pkgdef *pdef, int nodeps)
325 {
326 int i, marked = 0, matched = 0;
327 struct pkg *pkg, tmpkg, *findedpkg;
328@@ -851,10 +883,13 @@
329
330 i = n_array_bsearch_idx_ex(ps->pkgs, pdef->pkg, (tn_fn_cmp)pkg_cmp_name);
331 if (i < 0) {
332+ if (inst->flags & INSTS_CAPLOOKUP)
333+ return pkgset_mark_bycap(ps, inst, pdef);
334 logn(LOGERR, _("mark: %s not found"), pdef->pkg->name);
335 return 0;
336 }
337
338+
339 findedpkg = pkg = n_array_nth(ps->pkgs, i);
340
341 if (pkg_match_pkgdef(pkg, pdef)) {
342@@ -877,9 +912,10 @@
343 }
344 }
345
346+#if 0
347 if (!marked && !matched)
348 logn(LOGERR, _("mark: %s: versions not match"), pdef->pkg->name);
349-
350+#endif
351 return marked;
352 }
353
354@@ -924,6 +960,29 @@
355 return nerr;
356 }
357
358+static int pkgset_mark_verify_icaps(struct inst_s *inst)
359+{
360+ tn_array *keys;
361+ int i, j;
362+
363+ keys = n_hash_keys_cp(inst->icaps);
364+ for (i=0; i<n_array_size(keys); i++) {
365+ const char *cap = n_array_nth(keys, i);
366+ tn_array *pkgs = n_hash_get(inst->icaps, cap);
367+
368+ for (j=0; j < n_array_size(pkgs); j++) {
369+ struct pkg *pkg = n_array_nth(pkgs, j);
370+ if (pkg_is_marked(pkg)) {
371+ logn(LOGNOTICE, "%s: removed cap due to %s is marked",
372+ cap, pkg_snprintf_s0(pkg));
373+ n_hash_remove(inst->icaps, cap);
374+ break;
375+ }
376+ }
377+ }
378+ n_array_free(keys);
379+ return n_hash_size(inst->icaps);
380+}
381
382
383 int pkgset_mark_usrset(struct pkgset *ps, struct usrpkgset *ups,
384@@ -931,6 +990,7 @@
385 {
386 int i, nerr = 0, nodeps = 0, npatterns = 0;
387
388+ n_hash_clean(inst->icaps);
389 packages_mark(ps->pkgs, 0, PKG_INDIRMARK | PKG_DIRMARK);
390 //pkgset_mark(ps, PS_MARK_OFF_ALL);
391
392@@ -942,7 +1002,7 @@
393 for (i=0; i<n_array_size(ups->pkgdefs); i++) {
394 struct pkgdef *pdef = n_array_nth(ups->pkgdefs, i);
395 if (pdef->tflags & (PKGDEF_REGNAME | PKGDEF_PKGFILE)) {
396- if (!pkgset_mark_pkgdef_exact(ps, pdef, nodeps))
397+ if (!pkgset_mark_pkgdef_exact(ps, inst, pdef, nodeps))
398 nerr++;
399
400 } else if (pdef->tflags & PKGDEF_PATTERN) {
401@@ -950,6 +1010,7 @@
402
403 } else if (pdef->tflags & PKGDEF_VIRTUAL) { /* VIRTUAL implies OPTIONAL */
404 tn_array *avpkgs;
405+
406
407 #if 0
408 if (pdef->pkg == NULL) {
409@@ -1010,7 +1071,7 @@
410 if ((inst->flags & INSTS_CONFIRM_INST) && inst->ask_fn &&
411 inst->ask_fn(0, "Install %s? [y/N]", pdef->pkg->name));
412 #endif
413- if (!pkgset_mark_pkgdef_exact(ps, pdef, nodeps))
414+ if (!pkgset_mark_pkgdef_exact(ps, inst, pdef, nodeps))
415 nerr++;
416
417 } else {
418@@ -1036,7 +1097,8 @@
419 logn(LOGERR, _("Buggy package set."));
420 }
421 }
422-
423+
424+ pkgset_mark_verify_icaps(inst);
425 return nerr == 0;
426 }
427
428@@ -1056,8 +1118,40 @@
429 return n_array_nth(ps->pkgs, i);
430 }
431
432+tn_array *pkgset_lookup_cap(struct pkgset *ps, const char *capname)
433+{
434+ struct pkg **suspkgs, pkgsbuf[1024];
435+ int i, nsuspkgs = 0, found = 0;
436+ tn_array *pkgs = NULL;
437+ struct capreq *cap = capreq_new_name_a(capname);
438+
439+ DBGF("%s\n", capname);
440+
441+ found = psreq_lookup(ps, cap, &suspkgs, (struct pkg **)pkgsbuf, &nsuspkgs);
442+ if (found && nsuspkgs) {
443+ struct pkg **matches;
444+ int nmatches = 0, strict;
445+
446+ found = 0;
447+ matches = alloca(sizeof(*matches) * nsuspkgs);
448+ strict = ps->flags & PSVERIFY_MERCY ? 0 : 1;
449+ if (psreq_match_pkgs(NULL, cap, strict, suspkgs,
450+ nsuspkgs, matches, &nmatches)) {
451+ found = 1;
452+ pkgs = n_array_new(nmatches, NULL,
453+ (tn_fn_cmp)pkg_cmp_name_evr_rev);
454+
455+ if (nmatches > 0) {
456+ for (i=0; i < nmatches; i++)
457+ n_array_push(pkgs, matches[i]);
458+ }
459+ }
460+ }
461+ return pkgs;
462+}
463+
464
465-tn_array *pkgset_lookup_cap(struct pkgset *ps, const char *capname)
466+tn_array *pkgset_lookup_cap_OLD(struct pkgset *ps, const char *capname)
467 {
468 const struct capreq_idx_ent *ent;
469 tn_array *pkgs = NULL;
470Index: pkgset.h
471===================================================================
472RCS file: /cvsroot/installer/poldek/pkgset.h,v
473retrieving revision 1.37.4.2
474retrieving revision 1.37.4.3
475diff -u -r1.37.4.2 -r1.37.4.3
476--- pkgset.h 16 Feb 2004 19:39:57 -0000 1.37.4.2
477+++ pkgset.h 2 Jul 2004 17:42:40 -0000 1.37.4.3
478@@ -1,4 +1,4 @@
479-/* $Id$ */
480+/* $Id$ */
481 #ifndef POLDEK_PKGSET_H
482 #define POLDEK_PKGSET_H
483
484@@ -53,8 +53,8 @@
485 #define INSTS_JUSTFETCH (1 << 10)
486 #define INSTS_JUSTPRINT (1 << 11)
487 #define INSTS_JUSTPRINT_N (1 << 12) /* names, not filenames */
488-
489 #define INSTS_JUSTPRINTS (INSTS_JUSTPRINT | INSTS_JUSTPRINT_N)
490+#define INSTS_CAPLOOKUP (1 << 13)
491
492
493 #define INSTS_MKDBDIR (1 << 15) /* --mkdir */
494@@ -86,7 +86,8 @@
495 tn_array *rpmopts; /* rpm cmdline opts (char *opts[]) */
496 tn_array *rpmacros; /* rpm macros to pass to cmdline (char *opts[]) */
497 tn_array *hold_patterns;
498- tn_array *ign_patterns;
499+ tn_array *ign_patterns;
500+ tn_hash *icaps;
501
502 int (*askpkg_fn)(const char *, struct pkg **pkgs, struct pkg *deflt);
503 int (*ask_fn)(int default_a, const char *, ...);
504Index: rpm.c
505===================================================================
506RCS file: /cvsroot/installer/poldek/Attic/rpm.c,v
507retrieving revision 1.41.4.4
508retrieving revision 1.41.4.5
509diff -u -r1.41.4.4 -r1.41.4.5
510--- rpm.c 28 Jun 2004 20:18:39 -0000 1.41.4.4
511+++ rpm.c 2 Jul 2004 17:42:40 -0000 1.41.4.5
512@@ -11,7 +11,7 @@
513 */
514
515 /*
516- $Id$
517+ $Id$
518 */
519
520 #ifdef HAVE_CONFIG_H
521@@ -614,7 +614,7 @@
522
523 rpmdb_it_init(db, &it, RPMITER_CAP, capreq_name(cap));
524 while ((dbrec = rpmdb_it_get(&it))) {
525- if (dbpkg_array_has(unistdbpkgs, dbrec->recno))
526+ if (unistdbpkgs && dbpkg_array_has(unistdbpkgs, dbrec->recno))
527 continue;
528
529 if (dbpkgs == NULL)
530Index: usrset.c
531===================================================================
532RCS file: /cvsroot/installer/poldek/Attic/usrset.c,v
533retrieving revision 1.12.6.1
534retrieving revision 1.12.6.2
535diff -u -r1.12.6.1 -r1.12.6.2
536--- usrset.c 30 Dec 2003 18:19:52 -0000 1.12.6.1
537+++ usrset.c 2 Jul 2004 17:42:40 -0000 1.12.6.2
538@@ -7,7 +7,7 @@
539 */
540
541 /*
542- $Id$
543+ $Id$
544 */
545
546 #include <ctype.h>
547@@ -108,7 +108,7 @@
548 if (*p == '\0' || *p == '#')
549 return 0;
550
551- while (*p && !isalnum(*p)) {
552+ while (*p && !isalnum(*p) && *p != '/') {
553 switch (*p) {
554 case '~':
555 case '!': /* for backward compatybility */
556@@ -125,7 +125,7 @@
557 p++;
558 }
559
560- if (!isalnum(*p)) {
561+ if (!isalnum(*p) && *p != '/') {
562 if (nline > 0)
563 logn(LOGERR, _("%s:%d: syntax error"), fpath, nline);
564 else
565@@ -168,7 +168,7 @@
566
567
568 pdef = n_malloc(sizeof(*pdef) +
569- (virtname ? strlen(virtname) + 1 : 0));
570+ (virtname ? strlen(virtname) + 1 : 0));
571 pdef->tflags = tflags | deftyp;
572
573 if (name == NULL) {
This page took 0.277783 seconds and 4 git commands to generate.