Imported Upstream version 0.6.12
[platform/upstream/libsolv.git] / examples / solv.c
index a440b61..fc420b3 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
@@ -121,8 +124,8 @@ struct repoinfo {
   int metadata_expire;
   char **components;
   int ncomponents;
-
   unsigned char cookie[32];
+  int extcookieset;
   unsigned char extcookie[32];
   int incomplete;
 };
@@ -213,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)
 {
@@ -221,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)
 
@@ -475,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)
@@ -527,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);
@@ -1049,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));
@@ -1062,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);
@@ -1141,7 +1133,7 @@ usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
       fclose(fp);
       return 0;
     }
-  if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
+  if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)) != 0)
     {
       fclose(fp);
       return 0;
@@ -1173,6 +1165,7 @@ usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
     {
       memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
       memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
+      cinfo->extcookieset = 1;
     }
   if (mark)
     futimens(fileno(fp), 0);   /* try to set modification time */
@@ -1181,7 +1174,7 @@ usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
 }
 
 void
-writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
+writecachedrepo(Repo *repo, Repodata *repodata, const char *repoext, unsigned char *cookie)
 {
   FILE *fp;
   int i, fd;
@@ -1219,22 +1212,22 @@ writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *
   if (i < repo->end)
     onepiece = 0;
 
-  if (!info)
+  if (!repodata)
     repo_write(repo, fp);
   else if (repoext)
-    repodata_write(info, fp);
+    repodata_write(repodata, fp);
   else
     {
       int oldnrepodata = repo->nrepodata;
       repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata;   /* XXX: do this right */
       repo_write(repo, fp);
       repo->nrepodata = oldnrepodata;
-      onepiece = 0;
+      onepiece = 0;    /* don't bother for the added file provides */
     }
 
   if (!repoext && cinfo)
     {
-      if (!cinfo->extcookie[0])
+      if (!cinfo->extcookieset)
        {
          /* create the ext cookie and append it */
          /* we just need some unique ID */
@@ -1242,8 +1235,7 @@ writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *
          if (!fstat(fileno(fp), &stb))
            memset(&stb, 0, sizeof(stb));
          calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
-         if (cinfo->extcookie[0] == 0)
-           cinfo->extcookie[0] = 1;
+         cinfo->extcookieset = 1;
        }
       if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
        {
@@ -1289,12 +1281,12 @@ writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *
              int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
              /* make sure repodata contains complete repo */
              /* (this is how repodata_write saves it) */
-             repodata_extend_block(info, repo->start, repo->end - repo->start);
-             info->state = REPODATA_LOADING;
+             repodata_extend_block(repodata, repo->start, repo->end - repo->start);
+             repodata->state = REPODATA_LOADING;
              if (strcmp(repoext, "DL") != 0)
                flags |= REPO_LOCALPOOL;
              repo_add_solv(repo, fp, flags);
-             info->state = REPODATA_AVAILABLE; /* in case the load failed */
+             repodata->state = REPODATA_AVAILABLE;     /* in case the load failed */
            }
          fclose(fp);
        }
@@ -1408,7 +1400,8 @@ repomd_load_ext(Repo *repo, Repodata *data)
       printf("%s\n", pool_errstr(repo->pool));
       return 0;
     }
-  writecachedrepo(repo, data, ext, cinfo->extcookie);
+  if (cinfo->extcookieset)
+    writecachedrepo(repo, data, ext, cinfo->extcookie);
   return 1;
 }
 
@@ -1554,7 +1547,8 @@ susetags_load_ext(Repo *repo, Repodata *data)
       return 0;
     }
   fclose(fp);
-  writecachedrepo(repo, data, ext, cinfo->extcookie);
+  if (cinfo->extcookieset)
+    writecachedrepo(repo, data, ext, cinfo->extcookie);
   return 1;
 }
 #endif
@@ -1730,6 +1724,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))
@@ -1740,10 +1735,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");
@@ -2320,6 +2311,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);
@@ -2383,6 +2376,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)
@@ -2448,6 +2452,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";
@@ -2926,6 +2931,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)