poldek: poldek/pkgset-order.c, poldek/pkgset.h, poldek/poldek_ts.c...

mis mis at pld-linux.org
Sun Dec 17 18:33:30 CET 2006


Author: mis                          Date: Sun Dec 17 17:33:30 2006 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- new --verify=order to check prepreq's loops and packages ordering

---- Files affected:
poldek/poldek:
   pkgset-order.c (1.31 -> 1.32) , pkgset.h (1.59 -> 1.60) , poldek_ts.c (1.58 -> 1.59) 
poldek/poldek/cli:
   op_verify.c (1.14 -> 1.15) 

---- Diffs:

================================================================
Index: poldek/poldek/pkgset-order.c
diff -u poldek/poldek/pkgset-order.c:1.31 poldek/poldek/pkgset-order.c:1.32
--- poldek/poldek/pkgset-order.c:1.31	Sun Aug 20 20:14:58 2006
+++ poldek/poldek/pkgset-order.c	Sun Dec 17 18:33:25 2006
@@ -1,5 +1,5 @@
 /* 
-  Copyright (C) 2000 Pawel A. Gajda (mis at k2.net.pl)
+  Copyright (C) 2000-2007 Pawel A. Gajda (mis at pld-linux.org)
  
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License published by
@@ -27,13 +27,6 @@
 #include "misc.h"
 #include "pkgset-req.h"
 
-
-static void mapfn_clean_pkg_color(struct pkg *pkg) 
-{
-    pkg_set_color(pkg, PKG_COLOR_WHITE);
-    pkg_clr_prereqed(pkg);
-}
-
 /*
  * Ordering: sort packages topologically
  */
@@ -41,6 +34,7 @@
     tn_array *ordered_pkgs;
     tn_array *stack;
     int nerrors;
+    int verbose_level;
 };
 
 
@@ -49,42 +43,40 @@
                         unsigned reqpkg_flag, int deep) 
 {
     int i, last_stack_i = -1;
-
+    int verb = vs->verbose_level;
+    
     deep += 2;
     
     pkg_set_color(pkg, PKG_COLOR_GRAY);
     if (pkg->reqpkgs == NULL || n_array_size(pkg->reqpkgs) == 0) {
-        msg(4, "_\n");
-        msg_i(4, deep, "_ visit %s -> (NO REQS)", pkg->name);
+        msg(verb, "_\n");
+        msg_i(verb, deep, "_ visit %s  (NO REQS)", pkg->name);
         goto l_end;
     }
 
     n_array_push(vs->stack, pkg);
     last_stack_i = n_array_size(vs->stack) - 1;
     
-    if (poldek_VERBOSE > 2) {
-        msg(4, "_\n");
-        msg_i(4, deep, "_ visit %s -> (", pkg->name);
-        for (i=0; i < n_array_size(pkg->reqpkgs); i++) {
-            struct reqpkg *rp;	
-            
-            rp = n_array_nth(pkg->reqpkgs, i);
-            msg(4, "_%s%s, ", (rp->flags & reqpkg_flag) ? "*" : "",
-                rp->pkg->name);
+    msg(verb, "_\n");
+    msg_i(verb, deep, "_ visit %s -> (", pkg->name);
+    for (i=0; i < n_array_size(pkg->reqpkgs); i++) {
+        struct reqpkg *rp;	
+        
+        rp = n_array_nth(pkg->reqpkgs, i);
+        msg(verb, "_%s%s, ", (rp->flags & reqpkg_flag) ? "*" : "",
+            rp->pkg->name);
             
-            if (rp->flags & REQPKG_MULTI) {
-                int n = 0;
-                while (rp->adds[n]) {
-                    msg(4, "_%s%s, ",
-                        (rp->adds[n]->flags & reqpkg_flag) ? "*" : "",
-                        rp->adds[n]->pkg->name);
-                    n++;
-                }
+        if (rp->flags & REQPKG_MULTI) {
+            int n = 0;
+            while (rp->adds[n]) {
+                msg(verb, "_%s%s, ",
+                    (rp->adds[n]->flags & reqpkg_flag) ? "*" : "",
+                    rp->adds[n]->pkg->name);
+                n++;
             }
         }
-        msg(4, "_)\n");
-        msg_i(4, deep, "_ {");
     }
+    msg(verb, "_) {");
     
     for (i=0; i < n_array_size(pkg->reqpkgs); i++) {
         struct reqpkg *rpkg, *rp;
@@ -104,8 +96,8 @@
                     visit_install_order(vs, rp->pkg, reqpkg_flag, deep);
             
             } else if (pkg_is_color(rp->pkg, PKG_COLOR_BLACK)) {
-                msg(4, "_\n");
-                msg_i(4, deep, "_   visited %s", rp->pkg->name);
+                msg(verb, "_\n");
+                msg_i(verb, deep, "_   visited %s", rp->pkg->name);
                 
             } else if (pkg_is_color(rp->pkg, PKG_COLOR_GRAY)) { /* cycle  */
                 int is_loop = 0;
@@ -120,7 +112,6 @@
                             break;
 
                         n++;
-
                         if (!pkg_is_prereqed(p))
                             break;
 
@@ -134,9 +125,9 @@
                 if (is_loop) {
                     vs->nerrors++;
                     
-                    if (poldek_VERBOSE > 2) {
-                        msg(4, "\n");
-                        msg_i(4, deep, "   cycle   %s -> %s", pkg->name,
+                    if (verb > 2) {
+                        msg(verb, "\n");
+                        msg_i(verb, deep, "   cycle   %s -> %s", pkg->name,
                               rp->pkg->name);
 
                     } else {
@@ -147,7 +138,7 @@
                         error = alloca(size);
 
                         n = 0;
-                        n += n_snprintf(error, size, _("PreReq loop: "));
+                        n += n_snprintf(error, size, _("Requires(pre) loop: "));
                         n += n_snprintf(&error[n], size - n, "%s", rp->pkg->name);
                         for (i=n_array_size(vs->stack)-1; i >= 0; i--) {
                             struct pkg *p = n_array_nth(vs->stack, i);
@@ -157,8 +148,8 @@
                     }
                     
                 } else {
-                    msg(4, "\n");
-                    msg_i(4, deep, "   fakecycle   %s -> %s", pkg->name,
+                    msg(verb, "\n");
+                    msg_i(verb, deep, "   fakecycle   %s -> %s", pkg->name,
                           rp->pkg->name);
                 }
                 
@@ -172,22 +163,20 @@
         }
     }
     
-    if (poldek_VERBOSE > 3) {
-        msg(4, "\n");
-        msg_i(4, deep, "_ } ");
-        msg(4, "_%s",  pkg->name);
-        for (i=n_array_size(vs->stack)-2; i >= 0; i--) {
-            struct pkg *p = n_array_nth(vs->stack, i);
-            if (p != pkg)
-                msg(4, "_ <- %s", p->name);
-        }
+    msg(verb, "\n");
+    msg_i(verb, deep, "_ } ");
+    msg(verb, "_%s",  pkg->name);
+    for (i=n_array_size(vs->stack)-2; i >= 0; i--) {
+        struct pkg *p = n_array_nth(vs->stack, i);
+        if (p != pkg)
+            msg(verb, "_ <- %s", p->name);
     }
-    msg(4, "_\n");
+    msg(verb, "_\n");
 
  l_end:
     pkg_set_color(pkg, PKG_COLOR_BLACK);
     pkg_clr_prereqed(pkg);
-    msgn(4, "push %s", pkg_snprintf_s(pkg));
+    msgn(verb, "push %s", pkg_snprintf_s(pkg));
     n_array_push(vs->ordered_pkgs, pkg);
     if (last_stack_i != -1) 
         for (i=last_stack_i; i < n_array_size(vs->stack); i++) {
@@ -198,8 +187,14 @@
     return 0;
 }
 
+static void mapfn_clean_pkg_color(struct pkg *pkg) 
+{
+    pkg_set_color(pkg, PKG_COLOR_WHITE);
+    pkg_clr_prereqed(pkg);
+}
+
 static int do_order(tn_array *pkgs, tn_array **ordered_pkgs,
-                    unsigned reqpkg_flag)
+                    unsigned reqpkg_flag, int verbose_level)
 {
     struct pkg *pkg;
     struct visit_install_order_s vs;
@@ -209,6 +204,7 @@
 //                                  (tn_fn_free)pkg_free, NULL);
     vs.nerrors = 0;
     vs.stack = n_array_new(128, NULL, NULL);
+    vs.verbose_level = verbose_level;
     
     n_array_map(pkgs, (tn_fn_map1)mapfn_clean_pkg_color);
 
@@ -230,20 +226,21 @@
 
 
 /* RET: number of detected loops  */
-int packages_order(tn_array *pkgs, tn_array **ordered_pkgs, int ordertype)
+static int do_packages_order(tn_array *pkgs, tn_array **ordered_pkgs, int ordertype,
+                             int verbose_level)
 {
-    tn_array *ordered = NULL;
-    int nloops, verbose;
+    tn_array *preordered = NULL;
     unsigned reqpkg_flag = 0;
+    int nloops;
     
     n_assert(n_array_ctl_get_cmpfn(pkgs) == (tn_fn_cmp)pkg_cmp_name_evr_rev);
-    /* insertion sort - assuming pkgs are already sorted
+    /* insertion sort - assuming pkgs is already sorted
        by pkg_cmp_pri_name_evr_rev() */
     n_array_isort_ex(pkgs, (tn_fn_cmp)pkg_cmp_pri_name_evr_rev);
-    
-    verbose = poldek_set_verbose(-10);
-    do_order(pkgs, &ordered, 0);
-    poldek_set_verbose(verbose);
+
+    /* Preordering packages using Requires: */
+    msgn(verbose_level + 2, "Preordering packages...");
+    do_order(pkgs, &preordered, 0, verbose_level + 2);
     
     switch (ordertype) {
         case PKGORDER_INSTALL:
@@ -257,14 +254,45 @@
         default:
             n_assert(0);
     }
+    msgn(verbose_level + 2, "Ordering packages...");
     *ordered_pkgs = NULL;
-    nloops = do_order(ordered, ordered_pkgs, reqpkg_flag);
+    nloops = do_order(preordered, ordered_pkgs, reqpkg_flag, verbose_level + 1);
     
-    n_array_free(ordered);
+    n_array_free(preordered);
     n_array_isort(pkgs);
     
     return nloops;
 }
 
+int packages_order(tn_array *pkgs, tn_array **ordered, int ordertype)
+{
+    return do_packages_order(pkgs, ordered, ordertype, 3);
+}
+
+int packages_order_and_verify(tn_array *pkgs, tn_array **ordered, int ordertype,
+                              int verbose_level)
+{
+    int nloops, i;
 
+    msgn(verbose_level, _("Verifying packages ordering..."));
 
+    nloops = do_packages_order(pkgs, ordered, ordertype, verbose_level);
+    
+    if (nloops) {
+		logn(LOGERR, ngettext("%d prerequirement loop detected",
+                              "%d prerequirement loops detected",
+                              nloops), nloops);
+		
+    } else {
+        msgn(verbose_level, _("No loops -- OK"));
+    }
+    
+            
+    msgn(verbose_level, "Installation order:");
+    for (i=0; i < n_array_size(*ordered); i++) {
+        struct pkg *pkg = n_array_nth(*ordered, i);
+        msgn(verbose_level, "%d. %s", i, pkg_id(pkg));
+    }
+    msg(verbose_level, "\n");
+    return nloops == 0;
+}

================================================================
Index: poldek/poldek/pkgset.h
diff -u poldek/poldek/pkgset.h:1.59 poldek/poldek/pkgset.h:1.60
--- poldek/poldek/pkgset.h:1.59	Sun Aug 20 20:14:58 2006
+++ poldek/poldek/pkgset.h	Sun Dec 17 18:33:25 2006
@@ -38,14 +38,12 @@
 #define PKGORDER_INSTALL     1
 #define PKGORDER_UNINSTALL   2
 int packages_order(tn_array *pkgs, tn_array **ordered_pkgs, int ordertype);
-//int packages_order(tn_array *pkgs, tn_array **ordered_pkgs);
+
+int packages_order_and_verify(tn_array *pkgs, tn_array **ordered_pkgs,
+                              int ordertype, int verbose_level);
+
 int pkgset_order(struct pkgset *ps, int verbose);
 
-/* if set then:
- * - requirements matched even if requirement has version
- *   while capability hasn't (RPM style)
- * - files with different modes only are not assumed as conflicts
- */
 
 struct pm_ctx;
 struct pkgset *pkgset_new(struct pm_ctx *ctx);
@@ -54,6 +52,12 @@
 int pkgset_load(struct pkgset *ps, int ldflags, tn_array *sources);
 int pkgset_add_pkgdir(struct pkgset *ps, struct pkgdir *pkgdir);
 
+
+/* VRFY_MERCY - if set then:
+ * - requirements matched even if requirement has version
+ *   while capability hasn't (RPM style)
+ * - files with different modes only are not assumed as conflicts
+ */
 #define PSET_VRFY_MERCY          (1 << 0)
 #define PSET_VRFY_PROMOTEPOCH    (1 << 1)
 

================================================================
Index: poldek/poldek/poldek_ts.c
diff -u poldek/poldek/poldek_ts.c:1.58 poldek/poldek/poldek_ts.c:1.59
--- poldek/poldek/poldek_ts.c:1.58	Wed Aug 23 00:46:32 2006
+++ poldek/poldek/poldek_ts.c	Sun Dec 17 18:33:25 2006
@@ -1119,6 +1119,12 @@
             nerr++;
     }
 
+    if (ts->getop(ts, POLDEK_OP_VRFY_ORDER)) {
+        tn_array *ordered = NULL;
+        if (!packages_order_and_verify(pkgs, &ordered, PKGORDER_INSTALL, 1))
+            nerr++;
+    }
+
     if (ts->getop(ts, POLDEK_OP_VRFY_CNFLS)) {
         int i, j;
         msgn(0, _("Verifying conflicts..."));

================================================================
Index: poldek/poldek/cli/op_verify.c
diff -u poldek/poldek/cli/op_verify.c:1.14 poldek/poldek/cli/op_verify.c:1.15
--- poldek/poldek/cli/op_verify.c:1.14	Sun Jul 10 15:30:17 2005
+++ poldek/poldek/cli/op_verify.c	Sun Dec 17 18:33:25 2006
@@ -47,7 +47,7 @@
 static struct argp_option options[] = {
 {0,0,0,0, N_("Package set verification:"), OPT_GID},
 {"verify",  OPT_DEPS, "REPORT-TYPE...", OPTION_ARG_OPTIONAL,
-     N_("Verify package set, available reports are: 'deps', 'conflicts', "
+     N_("Verify package set, available reports are: 'deps', 'order', 'conflicts', "
         "'file-conflicts', 'file-orphans' and 'file-missing-deps'. "
         "Default is 'deps'."), OPT_GID },
 {"verify-conflicts",  OPT_CNFLS, 0, OPTION_HIDDEN, N_("Verify conflicts"), OPT_GID },
@@ -71,6 +71,7 @@
     int op;
 } verify_options[] = {
     { "deps", POLDEK_OP_VRFY_DEPS },
+    { "order", POLDEK_OP_VRFY_ORDER },
     { "conflicts", POLDEK_OP_VRFY_CNFLS }, 
     { "file-conflicts", POLDEK_OP_VRFY_FILECNFLS },
     { "file-orphans", POLDEK_OP_VRFY_FILEORPHANS },
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/pkgset-order.c?r1=1.31&r2=1.32&f=u
    http://cvs.pld-linux.org/poldek/poldek/pkgset.h?r1=1.59&r2=1.60&f=u
    http://cvs.pld-linux.org/poldek/poldek/poldek_ts.c?r1=1.58&r2=1.59&f=u
    http://cvs.pld-linux.org/poldek/poldek/cli/op_verify.c?r1=1.14&r2=1.15&f=u



More information about the pld-cvs-commit mailing list