Imported Upstream version 0.6.24
[platform/upstream/libsolv.git] / tools / installcheck.c
index e088aff..b0fdb33 100644 (file)
@@ -2,7 +2,7 @@
  */
 
 /*
- * Copyright (c) 2009, Novell Inc.
+ * Copyright (c) 2009-2015, SUSE LLC
  *
  * This program is licensed under the BSD license, read LICENSE.BSD
  * for further information
 #include "pool.h"
 #include "poolarch.h"
 #include "repo_solv.h"
-#ifndef DEBIAN
+#ifdef ENABLE_SUSEREPO
 #include "repo_susetags.h"
+#endif
+#ifdef ENABLE_RPMMD
 #include "repo_rpmmd.h"
-#else
+#endif
+#ifdef ENABLE_DEBIAN
 #include "repo_deb.h"
 #endif
+#ifdef ENABLE_ARCHREPO
+#include "repo_arch.h"
+#endif
 #include "solver.h"
 #include "solv_xfopen.h"
 
@@ -36,47 +42,78 @@ usage(char** argv)
   printf("Usage:\n%s: <arch> [options..] repo [--nocheck repo]...\n"
          "\t--exclude <pattern>\twhitespace-separated list of (sub-)"
          "packagenames to ignore\n"
+         "\t--withobsoletes\t\tCheck for obsoletes on packages contained in repos\n"
+         "\t--nocheck\t\tDo not warn about all following repos (only use them to fulfill dependencies)\n"
          "\t--withsrc\t\tAlso check dependencies of src.rpm\n\n"
          , argv[0]);
   exit(1);
 }
 
+#if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD) || defined(ENABLE_DEBIAN) || defined(ENABLE_ARCHREPO)
+static int
+strlen_comp(const char *str)
+{
+  size_t l = strlen(str);
+  if (l > 3 && !strcmp(str + l - 3, ".gz"))
+    return l - 3;
+  if (l > 3 && !strcmp(str + l - 3, ".xz"))
+    return l - 3;
+  if (l > 4 && !strcmp(str + l - 4, ".bz2"))
+    return l - 4;
+  if (l > 5 && !strcmp(str + l - 4, ".lzma"))
+    return l - 5;
+  return l;
+}
+#endif
 
 int
 main(int argc, char **argv)
 {
   Pool *pool;
   Solver *solv;
+  Repo *repo;
   Queue job;
   Queue rids;
   Queue cand;
-  Queue archlocks;
   char *arch, *exclude_pat;
   int i, j;
   Id p;
-  Id rpmid, rpmarch, rpmrel, archlock;
+  Id archid, noarchid;
+  Id rpmrel;
+#ifndef DEBIAN
+  Id rpmid;
+#endif
   int status = 0;
   int nocheck = 0;
   int withsrc = 0;
+  int obsoletepkgcheck = 0;
 
   exclude_pat = 0;
-  archlock = 0;
   if (argc < 3)
     usage(argv);
 
   arch = argv[1];
   pool = pool_create();
   pool_setarch(pool, arch);
+  noarchid = pool->solvables[SYSTEMSOLVABLE].arch;
   for (i = 2; i < argc; i++)
     {
       FILE *fp;
+      int r;
+#if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD) || defined(ENABLE_DEBIAN) || defined(ENABLE_ARCHREPO)
       int l;
+#endif
 
       if (!strcmp(argv[i], "--withsrc"))
        {
          withsrc++;
          continue;
        }
+      if (!strcmp(argv[i], "--withobsoletes"))
+        {
+          obsoletepkgcheck++;
+          continue;
+        }
       if (!strcmp(argv[i], "--nocheck"))
        {
          if (!nocheck)
@@ -94,7 +131,9 @@ main(int argc, char **argv)
           ++i;
           continue;
         }
-      l = strlen(argv[i]);
+#if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD) || defined(ENABLE_DEBIAN) || defined(ENABLE_ARCHREPO)
+      l = strlen_comp(argv[i]);
+#endif
       if (!strcmp(argv[i], "-"))
        fp = stdin;
       else if ((fp = solv_xfopen(argv[i], 0)) == 0)
@@ -102,33 +141,55 @@ main(int argc, char **argv)
          perror(argv[i]);
          exit(1);
        }
-      Repo *repo = repo_create(pool, argv[i]);
-#ifndef DEBIAN
-      if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
-       {
-         repo_add_susetags(repo, fp, 0, 0, 0);
-       }
-      else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
-       {
-         repo_add_susetags(repo, fp, 0, 0, 0);
-       }
-      else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
+      repo = repo_create(pool, argv[i]);
+      r = 0;
+      if (0)
+        {
+        }
+#ifdef ENABLE_SUSEREPO
+      else if (l >= 8 && !strncmp(argv[i] + l - 8, "packages", 8))
        {
-         repo_add_rpmmd(repo, fp, 0, 0);
+         r = repo_add_susetags(repo, fp, 0, 0, 0);
        }
-#else
-      if (l >= 8 && !strcmp(argv[i] + l - 8, "Packages"))
+#endif
+#ifdef ENABLE_RPMMD
+      else if (l >= 11 && !strncmp(argv[i] + l - 11, "primary.xml", 11))
        {
-         repo_add_debpackages(repo, fp, 0);
+         r = repo_add_rpmmd(repo, fp, 0, 0);
+          if (!r && i + 1 < argc)
+            {
+              l = strlen_comp(argv[i + 1]);
+              if (l >= 13 && !strncmp(argv[i + 1] + l - 13, "filelists.xml", 13))
+                {
+                  i++;
+                  fclose(fp);
+                  if ((fp = solv_xfopen(argv[i], 0)) == 0)
+                    {
+                      perror(argv[i]);
+                      exit(1);
+                    }
+                  r = repo_add_rpmmd(repo, fp, 0, REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
+                }
+            }
        }
-      else if (l >= 11 && !strcmp(argv[i] + l - 11, "Packages.gz"))
+#endif
+#ifdef ENABLE_DEBIAN
+      else if (l >= 8 && !strncmp(argv[i] + l - 8, "Packages", 8))
        {
-         repo_add_debpackages(repo, fp, 0);
+         r = repo_add_debpackages(repo, fp, 0);
        }
 #endif
-      else if (repo_add_solv(repo, fp))
+#ifdef ENABLE_ARCHREPO
+      else if (l >= 7 && (!strncmp(argv[i] + l - 7, ".db.tar", 7)))
+        {
+         r = repo_add_arch_repo(repo, fp, 0);
+        }
+#endif
+      else
+       r = repo_add_solv(repo, fp, 0);
+      if (r)
        {
-         fprintf(stderr, "could not add repo %s\n", argv[i]);
+         fprintf(stderr, "could not add repo %s: %s\n", argv[i], pool_errstr(pool));
          exit(1);
        }
       if (fp != stdin)
@@ -136,28 +197,29 @@ main(int argc, char **argv)
     }
   pool_addfileprovides(pool);
   pool_createwhatprovides(pool);
+  archid = pool_str2id(pool, arch, 0);
+#ifndef DEBIAN
   rpmid = pool_str2id(pool, "rpm", 0);
-  rpmarch = pool_str2id(pool, arch, 0);
   rpmrel = 0;
-#ifndef DEBIAN
-  if (rpmid && rpmarch)
+  if (rpmid && archid)
     {
       for (p = 1; p < pool->nsolvables; p++)
        {
          Solvable *s = pool->solvables + p;
-         if (s->name == rpmid && s->arch == rpmarch)
+         if (s->name == rpmid && s->arch == archid && pool_installable(pool, s))
            break;
        }
       if (p < pool->nsolvables)
-        rpmrel = pool_rel2id(pool, rpmid, rpmarch, REL_ARCH, 1);
+        rpmrel = pool_rel2id(pool, rpmid, archid, REL_ARCH, 1);
     }
+#else
+  rpmrel = 0;
 #endif
   
   queue_init(&job);
   queue_init(&rids);
   queue_init(&cand);
-  queue_init(&archlocks);
-  for (p = 1; p < pool->nsolvables; p++)
+  for (p = 1; p < (nocheck ? nocheck : pool->nsolvables); p++)
     {
       Solvable *s = pool->solvables + p;
       if (!s->repo)
@@ -169,50 +231,73 @@ main(int argc, char **argv)
        }
       if (!pool_installable(pool, s))
        continue;
-      if (rpmrel && s->arch != rpmarch)
+      if (archid && s->arch != archid && s->arch != noarchid)
        {
+         /* check if we will conflict with a infarch rule, if yes,
+          * don't bother checking the package */
          Id rp, rpp;
          FOR_PROVIDES(rp, rpp, s->name)
            {
              if (pool->solvables[rp].name != s->name)
                continue;
-             if (pool->solvables[rp].arch == rpmarch)
+             if (pool->solvables[rp].arch == archid)
                break;
            }
          if (rp)
-           {
-             queue_push(&archlocks, p);
-             continue;
-           }
+           continue;
        }
       queue_push(&cand, p);
     }
-  
-  if (archlocks.count)
+  if (obsoletepkgcheck)
     {
-      archlock = pool_queuetowhatprovides(pool, &archlocks);
+      int obsoleteusesprovides = pool_get_flag(pool, POOL_FLAG_OBSOLETEUSESPROVIDES);
+      int obsoleteusescolors = pool_get_flag(pool, POOL_FLAG_OBSOLETEUSESCOLORS);
+
+      for (i = 0; i < cand.count; i++)
+       {
+         Solvable *s;
+         s = pool->solvables + cand.elements[i];
+
+         if (s->obsoletes)
+           {
+             Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
+
+             while ((obs = *obsp++) != 0)
+               {
+                 Id op, opp;
+                 FOR_PROVIDES(op, opp, obs)
+                   {
+                     Solvable *os = pool->solvables + op;
+                     if (nocheck && op >= nocheck)
+                       continue;
+                     if (solvable_identical(s, os))
+                       continue;
+                     if (!obsoleteusesprovides && !pool_match_nevr(pool, os, obs))
+                       continue;
+                     if (obsoleteusescolors && !pool_colormatch(pool, s, os))
+                       continue;
+                     status = 2;
+                     printf("can't install %s:\n", pool_solvid2str(pool, op));
+                     printf("  package is obsoleted by %s\n", pool_solvable2str(pool, s));
+                   }
+               }
+           }
+       }
     }
+
+  solv = solver_create(pool);
+
   /* prune cand by doing weak installs */
   while (cand.count)
     {
-      solv = solver_create(pool);
       queue_empty(&job);
       for (i = 0; i < cand.count; i++)
        {
          p = cand.elements[i];
-         queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
-         queue_push(&job, p);
+         queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK, p);
        }
       if (rpmrel)
-       {
-         queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
-         queue_push(&job, rpmrel);
-       }
-      if (archlock)
-       {
-         queue_push(&job, SOLVER_LOCK|SOLVER_SOLVABLE_ONE_OF);
-         queue_push(&job, archlock);
-       }
+       queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME, rpmrel);
       solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
       solver_solve(solv, &job);
       /* prune... */
@@ -224,14 +309,6 @@ main(int argc, char **argv)
              cand.elements[j++] = p;
              continue;
            }
-#if 0
-         Solvable *s = pool->solvables + p;
-         if (!strcmp(pool_id2str(pool, s->name), "libusb-compat-devel"))
-           {
-             cand.elements[j++] = p;
-             continue;
-           }
-#endif
        }
       cand.count = j;
       if (i == j)
@@ -245,13 +322,11 @@ main(int argc, char **argv)
       int problemcount;
 
       p = cand.elements[i];
-      if (nocheck && p >= nocheck)
-       continue;
       if (exclude_pat)
         {
           char *ptr, *save = 0, *pattern;
           int match = 0;
-          pattern = strdup(exclude_pat);
+          pattern = solv_strdup(exclude_pat);
 
           for (ptr = strtok_r(pattern, " ", &save);
               ptr;
@@ -263,25 +338,15 @@ main(int argc, char **argv)
                   break;
                 }
             }
-          free(pattern);
+          solv_free(pattern);
           if (match)
             continue;
         }
       s = pool->solvables + p;
-      solv = solver_create(pool);
       queue_empty(&job);
-      queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
-      queue_push(&job, p);
+      queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE, p);
       if (rpmrel)
-       {
-         queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
-         queue_push(&job, rpmrel);
-       }
-      if (archlock)
-       {
-         queue_push(&job, SOLVER_LOCK|SOLVER_SOLVABLE_ONE_OF);
-         queue_push(&job, archlock);
-       }
+       queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME, rpmrel);
       solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
       problemcount = solver_solve(solv, &job);
       if (problemcount)
@@ -317,8 +382,13 @@ main(int argc, char **argv)
                          printf("  %s has inferior architecture\n", pool_solvable2str(pool, s));
                          break;
                        case SOLVER_RULE_UPDATE:
+                         s = pool_id2solvable(pool, source);
+                         printf("  %s can not be updated\n", pool_solvable2str(pool, s));
                          break;
                        case SOLVER_RULE_JOB:
+                       case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
+                       case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
+                       case SOLVER_RULE_JOB_UNSUPPORTED:
                          break;
                        case SOLVER_RULE_RPM:
                          printf("  some dependency problem\n");
@@ -372,16 +442,7 @@ main(int argc, char **argv)
                }
            }
        }
-#if 0
-      else
-       {
-         if (!strcmp(pool_id2str(pool, s->name), "libusb-compat-devel"))
-           {
-             solver_printdecisions(solv);
-           }
-       }
-#endif
-      solver_free(solv);
     }
+  solver_free(solv);
   exit(status);
 }