Imported Upstream version 0.6.7
[platform/upstream/libsolv.git] / examples / solv.c
index b6bf9d4..8b0d6cc 100644 (file)
 #include "repo_updateinfoxml.h"
 #include "repo_deltainfoxml.h"
 #endif
+#ifdef ENABLE_APPDATA
+#include "repo_appdata.h"
+#endif
 #ifdef ENABLE_SUSEREPO
 #include "repo_products.h"
 #include "repo_susetags.h"
 #include "repo_content.h"
 #endif
+#ifdef SUSE
+#include "repo_autopattern.h"
+#endif
 #include "solv_xfopen.h"
 
 #ifdef FEDORA
@@ -91,6 +97,9 @@
 # define PRODUCTS_PATH "/etc/products.d"
 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
 #endif
+#ifdef ENABLE_APPDATA
+# define APPDATA_PATH "/usr/share/appdata"
+#endif
 
 #define SOLVCACHE_PATH "/var/cache/solv"
 
@@ -207,7 +216,6 @@ yum_substitute(Pool *pool, char *line)
 #define TYPE_PLAINDIR  3
 #define TYPE_DEBIAN     4
 
-#ifndef NOSYSTEM
 static int
 read_repoinfos_sort(const void *ap, const void *bp)
 {
@@ -215,7 +223,6 @@ read_repoinfos_sort(const void *ap, const void *bp)
   const struct repoinfo *b = bp;
   return strcmp(a->alias, b->alias);
 }
-#endif
 
 #if defined(SUSE) || defined(FEDORA)
 
@@ -469,15 +476,6 @@ read_repoinfos(Pool *pool, int *nrepoinfosp)
 
 #endif
 
-#ifdef NOSYSTEM
-struct repoinfo *
-read_repoinfos(Pool *pool, int *nrepoinfosp)
-{
-  *nrepoinfosp = 0;
-  return 0;
-}
-#endif
-
 
 void
 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
@@ -521,7 +519,7 @@ verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksum
 {
   char buf[1024];
   const unsigned char *sum;
-  void *h;
+  Chksum *h;
   int l;
 
   h = solv_chksum_create(chksumtype);
@@ -1009,7 +1007,7 @@ read_sigs()
 {
   Pool *sigpool = pool_create();
 #if defined(ENABLE_PUBKEY) && defined(ENABLE_RPMDB)
-  Repo *repo = repo_create(sigpool, "rpmdbkeys");
+  Repo *repo = repo_create(sigpool, "pubkeys");
   repo_add_rpmdb_pubkeys(repo, 0);
 #endif
   return sigpool;
@@ -1043,7 +1041,7 @@ void
 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
 {
   char buf[4096];
-  void *h = solv_chksum_create(chktype);
+  Chksum *h = solv_chksum_create(chktype);
   int l;
 
   solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
@@ -1056,7 +1054,7 @@ calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
 void
 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
 {
-  void *h = solv_chksum_create(chktype);
+  Chksum *h = solv_chksum_create(chktype);
   solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
   if (cookie)
     solv_chksum_add(h, cookie, 32);
@@ -1724,6 +1722,7 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
 #endif
 
   repo = repo_create(pool, "@System");
+  memset(&stb, 0, sizeof(stb));
 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
   printf("rpm database:");
   if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
@@ -1734,10 +1733,6 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
   if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
     memset(&stb, 0, sizeof(stb));
 #endif
-#ifdef NOSYSTEM
-  printf("no installed database:");
-  memset(&stb, 0, sizeof(stb));
-#endif
   calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
   if (usecachedrepo(repo, 0, installedcookie, 0))
     printf(" cached\n");
@@ -1750,14 +1745,21 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
 
 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
-      if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
+      if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
        {
          fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
          exit(1);
        }
 # endif
+# if defined(ENABLE_APPDATA)
+      if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
+       {
+         fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool));
+         exit(1);
+       }
+# endif
       ofp = fopen(calccachepath(repo, 0, 0), "r");
-      if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
+      if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
        {
          fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
          exit(1);
@@ -1766,12 +1768,13 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
         fclose(ofp);
 #endif
 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
-      if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
+      if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
        {
          fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
          exit(1);
        }
 #endif
+      repo_internalize(repo);
       writecachedrepo(repo, 0, 0, installedcookie);
     }
   pool_set_installed(pool, repo);
@@ -1856,6 +1859,18 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
              fclose(fp);
            }
 
+#ifdef ENABLE_APPDATA
+         filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
+         if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
+           {
+             if (repo_add_appdata(repo, fp, 0))
+               {
+                 printf("appdata: %s\n", pool_errstr(pool));
+                 cinfo->incomplete = 1;
+               }
+             fclose(fp);
+           }
+#endif
          data = repo_add_repodata(repo, 0);
          if (!repomd_add_ext(repo, data, "deltainfo"))
            repomd_add_ext(repo, data, "prestodelta");
@@ -1966,6 +1981,20 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
                  fclose(fp);
                }
            }
+#ifdef ENABLE_APPDATA
+         filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
+          if (!filename)
+           filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
+         if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
+           {
+             if (repo_add_appdata(repo, fp, 0))
+               {
+                 printf("appdata: %s\n", pool_errstr(pool));
+                 cinfo->incomplete = 1;
+               }
+             fclose(fp);
+           }
+#endif
           repo_internalize(repo);
          data = repo_add_repodata(repo, 0);
          susetags_add_ext(repo, data);
@@ -2199,28 +2228,6 @@ rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
 static Id
 nscallback(Pool *pool, void *data, Id name, Id evr)
 {
-  if (name == NAMESPACE_PRODUCTBUDDY)
-    {
-      /* SUSE specific hack: each product has an associated rpm */
-      Solvable *s = pool->solvables + evr;
-      Id p, pp, cap;
-      Id bestp = 0;
-
-      cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
-      if (!cap)
-        return 0;
-      cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
-      if (!cap)
-        return 0;
-      FOR_PROVIDES(p, pp, cap)
-        {
-          Solvable *ps = pool->solvables + p;
-          if (ps->repo == s->repo && ps->arch == s->arch)
-            if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
-             bestp = p;
-        }
-      return bestp;
-    }
 #if 0
   if (name == NAMESPACE_LANGUAGE)
     {
@@ -2302,6 +2309,8 @@ rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_ins
       if (repo->nrepodata < 2)
        continue;
       cinfo = repo->appdata;
+      if (repo != pool->installed && !cinfo)
+       continue;
       if (cinfo && cinfo->incomplete)
        continue;
       data = repo_id2repodata(repo, 1);
@@ -2365,6 +2374,17 @@ addfileprovides(Pool *pool)
 
 #endif
 
+#ifdef SUSE
+static void
+add_autopackages(Pool *pool)
+{
+  int i;
+  Repo *repo;
+  FOR_REPOS(i, repo)
+    repo_add_autopattern(repo, 0);
+}
+#endif
+
 #if defined(SUSE) || defined(FEDORA)
 static void
 add_patchjobs(Pool *pool, Queue *job)
@@ -2430,6 +2450,7 @@ showdiskusagechanges(Transaction *trans)
   int i;
 
   /* XXX: use mountpoints here */
+  memset(duc, 0, sizeof(duc));
   duc[0].path = "/";
   duc[1].path = "/usr/share/man";
   duc[2].path = "/sbin";
@@ -2602,12 +2623,19 @@ main(int argc, char **argv)
   int forcebest = 0;
   char *rootdir = 0;
   char *keyname = 0;
+  int debuglevel = 0;
 
   argc--;
   argv++;
   userhome = getenv("HOME");
   if (userhome && userhome[0] != '/')
     userhome = 0;
+  while (argc && !strcmp(argv[0], "-d"))
+    {
+      debuglevel++;
+      argc--;
+      argv++;
+    }
   if (!argv[0])
     usage(1);
   if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
@@ -2709,7 +2737,8 @@ main(int argc, char **argv)
 #ifdef SUSE
   pool->nscallback = nscallback;
 #endif
-  // pool_setdebuglevel(pool, 2);
+  if (debuglevel)
+    pool_setdebuglevel(pool, debuglevel);
   setarch(pool);
   pool_set_flag(pool, POOL_FLAG_ADDFILEPROVIDESFILTERED, 1);
   repoinfos = read_repoinfos(pool, &nrepoinfos);
@@ -2733,9 +2762,15 @@ main(int argc, char **argv)
   queue_init(&repofilter);
   queue_init(&kindfilter);
   queue_init(&archfilter);
-  while (argc > 2)
+  while (argc > 1)
     {
-      if (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo"))
+      if (!strcmp(argv[1], "-i"))
+       {
+         queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO, pool->installed->repoid);
+         argc--;
+         argv++;
+       }
+      else if (argc > 2 && (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo")))
        {
          const char *rname = argv[2], *rp;
          Id repoid = 0;
@@ -2775,15 +2810,15 @@ main(int argc, char **argv)
          argc -= 2;
          argv += 2;
        }
-      else if (!strcmp(argv[1], "--arch"))
+      else if (argc > 2 && !strcmp(argv[1], "--arch"))
        {
-         if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc")) 
+         if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc"))
            archfilter_src = 1;
          queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, argv[2], 1), REL_ARCH, 1));
          argc -= 2;
          argv += 2;
        }
-      else if (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type"))
+      else if (argc > 2 && (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type")))
        {
          const char *kind = argv[2];
          if (!strcmp(kind, "srcpackage"))
@@ -2846,7 +2881,7 @@ main(int argc, char **argv)
     }
 
   /* process command line packages */
-  if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
+  if (mainmode == MODE_LIST || mainmode == MODE_INFO || mainmode == MODE_INSTALL)
     {
       for (i = 1; i < argc; i++)
        {
@@ -2894,6 +2929,9 @@ main(int argc, char **argv)
   if (pool->disttype == DISTTYPE_RPM)
     addfileprovides(pool);
 #endif
+#ifdef SUSE
+  add_autopackages(pool);
+#endif
   pool_createwhatprovides(pool);
 
   if (keyname)
@@ -3208,6 +3246,8 @@ rerunsolver:
          if (s->repo == commandlinerepo)
            {
              loc = solvable_lookup_location(s, &medianr);
+             if (!loc)
+               continue;
              if (!(newpkgsfps[i] = fopen(loc, "r")))
                {
                  perror(loc);