Imported Upstream version 0.6.8
[platform/upstream/libsolv.git] / ext / repo_zyppdb.c
index e511872..5200c29 100644 (file)
 #include <assert.h>
 #include <dirent.h>
 #include <expat.h>
+#include <errno.h>
 
 #include "pool.h"
 #include "repo.h"
 #include "util.h"
 #define DISABLE_SPLIT
 #include "tools_util.h"
-#include "repo_content.h"
+#include "repo_zyppdb.h"
 
 
-//#define DUMPOUT 0
-
 enum state {
-  STATE_START,           // 0
-  STATE_PRODUCT,         // 1
-  STATE_NAME,            // 2
-  STATE_VERSION,         // 3
-  STATE_ARCH,            // 4
-  STATE_SUMMARY,         // 5
-  STATE_VENDOR,          // 6
-  STATE_INSTALLTIME,     // 7
-  NUMSTATES              // 0
+  STATE_START,
+  STATE_PRODUCT,
+  STATE_NAME,
+  STATE_VERSION,
+  STATE_ARCH,
+  STATE_SUMMARY,
+  STATE_VENDOR,
+  STATE_INSTALLTIME,
+  NUMSTATES
 };
 
 struct stateswitch {
@@ -162,7 +161,6 @@ startElement(void *userData, const char *name, const char **atts)
        /* parse 'type' */
        const char *type = find_attr("type", atts);
        s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
-       repodata_extend(pd->data, s - pool->solvables);
        pd->handle = s - pool->solvables;
        if (type)
          repodata_set_str(pd->data, pd->handle, PRODUCT_TYPE, type);
@@ -291,6 +289,11 @@ add_zyppdb_product(struct parsedata *pd, FILE *fp)
       if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
        {
          pool_debug(pd->pool, SOLV_ERROR, "repo_zyppdb: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+         if (pd->solvable)
+           {
+             repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1);
+             pd->solvable = 0;
+           }
          return;
        }
       if (l == 0)
@@ -306,7 +309,7 @@ add_zyppdb_product(struct parsedata *pd, FILE *fp)
  * parse each one as a product
  */
 
-void
+int
 repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
 {
   int i;
@@ -317,7 +320,7 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
   DIR *dir;
   FILE *fp;
   Repodata *data;
-  
+
   data = repo_add_repodata(repo, flags);
   memset(&pd, 0, sizeof(pd));
   pd.repo = repo;
@@ -334,6 +337,8 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
       pd.sbtab[sw->to] = sw->from;
     }
 
+  if (flags & REPO_USE_ROOTDIR)
+    dirpath = pool_prepend_rootdir(repo->pool, dirpath);
   dir = opendir(dirpath);
   if (dir)
     {
@@ -344,7 +349,7 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
          fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
          if ((fp = fopen(fullpath, "r")) == 0)
            {
-             perror(fullpath);
+             pool_error(repo->pool, 0, "%s: %s", fullpath, strerror(errno));
              continue;
            }
          add_zyppdb_product(&pd, fp);
@@ -355,8 +360,11 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
 
   free(pd.content);
   join_freemem(&pd.jd);
+  if (flags & REPO_USE_ROOTDIR)
+    solv_free((char *)dirpath);
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
+  return 0;
 }
 
 /* EOF */