Merge pull request #44 from akozumpl/archs
[platform/upstream/libsolv.git] / examples / solv.c
index cdb69e9..d9b03a1 100644 (file)
@@ -84,6 +84,9 @@
 #include "repo_susetags.h"
 #include "repo_content.h"
 #endif
+#ifdef SUSE
+#include "repo_autopattern.h"
+#endif
 #include "solv_xfopen.h"
 
 #ifdef FEDORA
@@ -527,7 +530,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);
@@ -1049,7 +1052,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));
@@ -1062,7 +1065,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);
@@ -1756,21 +1759,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_NO_INTERNALIZE | REPO_USE_ROOTDIR))
+      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);
@@ -1779,12 +1782,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);
@@ -2319,6 +2323,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);
@@ -2382,6 +2388,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)
@@ -2758,9 +2775,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;
@@ -2800,7 +2823,7 @@ 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"))
            archfilter_src = 1;
@@ -2808,7 +2831,7 @@ main(int argc, char **argv)
          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"))
@@ -2919,6 +2942,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)