Imported Upstream version 0.7.12
[platform/upstream/libsolv.git] / ext / repo_releasefile_products.c
index 9277395..a40bc98 100644 (file)
@@ -19,6 +19,7 @@
 #include <assert.h>
 #include <dirent.h>
 #include <ctype.h>
+#include <errno.h>
 
 #include "pool.h"
 #include "repo.h"
 
 #define BUFF_SIZE 8192
 
+struct parsedata {
+  Repo *repo;
+  struct joindata jd;
+};
+
 static void
-add_releasefile_product(Repo *repo, FILE *fp)
+add_releasefile_product(struct parsedata *pd, FILE *fp)
 {
+  Repo *repo = pd->repo;
   Pool *pool = repo->pool;
   char buf[BUFF_SIZE];
   Id name = 0;
@@ -66,7 +73,7 @@ add_releasefile_product(Repo *repo, FILE *fp)
                 && (*ptr1 == ' ' || isdigit(*ptr1) || *ptr1 == '.'))
            --ptr1;
          *(++ptr1) = 0;
-         name = str2id(pool, join2("product", ":", buf), 1);
+         name = pool_str2id(pool, join2(&pd->jd, "product", ":", buf), 1);
 
          if (ptr)
            {
@@ -83,7 +90,7 @@ add_releasefile_product(Repo *repo, FILE *fp)
                         *ptr1 = tolower(*ptr1);
                      ++ptr1;
                    }
-                 arch = str2id(pool, ptr, 1);
+                 arch = pool_str2id(pool, ptr, 1);
                }
            }
        }
@@ -102,28 +109,37 @@ add_releasefile_product(Repo *repo, FILE *fp)
     {
       Solvable *s = pool_id2solvable(pool, repo_add_solvable(repo));
       s->name = name;
-      if (version)
-       s->evr = version;
-      if (arch)
-       s->arch = arch;
-      if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
-       s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
+      s->evr = version ? version : ID_EMPTY;
+      s->arch = arch ? arch : ARCH_NOARCH;
+      if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
+       s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
     }
 }
 
 
-void
+int
 repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
 {
   DIR *dir;
   struct dirent *entry;
   FILE *fp;
   char *fullpath;
+  struct parsedata pd;
 
+  if (!dirpath)
+    dirpath = "/etc";
+  if (flags & REPO_USE_ROOTDIR)
+    dirpath = pool_prepend_rootdir(repo->pool, dirpath);
   dir = opendir(dirpath);
   if (!dir)
-    return;
+    {
+      if (flags & REPO_USE_ROOTDIR)
+        solv_free((char *)dirpath);
+      return 0;
+    }
 
+  memset(&pd, 0, sizeof(pd));
+  pd.repo = repo;
   while ((entry = readdir(dir)))
     {
       int len = strlen(entry->d_name);
@@ -132,19 +148,23 @@ repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
          /* skip /etc/lsb-release, thats not a product per-se */
          if (strcmp(entry->d_name, "lsb-release") == 0)
            continue;
-         fullpath = join2(dirpath, "/", entry->d_name);
+         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_releasefile_product(repo, fp);
+         add_releasefile_product(&pd, fp);
+         fclose(fp);
        }
     }
   closedir(dir);
-  join_freemem();
+  join_freemem(&pd.jd);
+  if (flags & REPO_USE_ROOTDIR)
+    solv_free((char *)dirpath);
 
   if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
     repodata_internalize(repo_last_repodata(repo));
+  return 0;
 }