4 * Parses all files below 'proddir'
5 * See http://en.opensuse.org/Product_Management/Code11
8 * Copyright (c) 2008, Novell Inc.
10 * This program is licensed under the BSD license, read LICENSE.BSD
11 * for further information
14 #include <sys/types.h>
27 #include "tools_util.h"
28 #include "repo_releasefile_products.h"
30 #define BUFF_SIZE 8192
38 add_releasefile_product(struct parsedata *pd, FILE *fp)
40 Repo *repo = pd->repo;
41 Pool *pool = repo->pool;
46 int lnum = 0; /* line number */
49 /* parse /etc/<xyz>-release file */
50 while (fgets(buf, sizeof(buf), fp))
52 /* remove trailing \n */
54 if (l && buf[l - 1] == '\n')
60 /* 1st line, <name> [(<arch>)] */
61 ptr = strchr(buf, '(');
70 /* track back until non-blank, non-digit */
72 && (*ptr1 == ' ' || isdigit(*ptr1) || *ptr1 == '.'))
75 name = pool_str2id(pool, join2(&pd->jd, "product", ":", buf), 1);
80 char *ptr1 = strchr(ptr, ')');
89 *ptr1 = tolower(*ptr1);
92 arch = pool_str2id(pool, ptr, 1);
96 else if (strncmp(buf, "VERSION", 7) == 0)
98 ptr = strchr(buf + 7, '=');
101 while (*++ptr == ' ')
103 version = makeevr(pool, ptr);
109 Solvable *s = pool_id2solvable(pool, repo_add_solvable(repo));
111 s->evr = version ? version : ID_EMPTY;
112 s->arch = arch ? arch : ARCH_NOARCH;
113 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
114 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
120 repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
123 struct dirent *entry;
130 if (flags & REPO_USE_ROOTDIR)
131 dirpath = pool_prepend_rootdir(repo->pool, dirpath);
132 dir = opendir(dirpath);
135 if (flags & REPO_USE_ROOTDIR)
136 solv_free((char *)dirpath);
140 memset(&pd, 0, sizeof(pd));
142 while ((entry = readdir(dir)))
144 int len = strlen(entry->d_name);
145 if (len > 8 && !strcmp(entry->d_name + len - 8, "-release"))
147 /* skip /etc/lsb-release, thats not a product per-se */
148 if (strcmp(entry->d_name, "lsb-release") == 0)
150 fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
151 if ((fp = fopen(fullpath, "r")) == 0)
156 add_releasefile_product(&pd, fp);
161 join_freemem(&pd.jd);
162 if (flags & REPO_USE_ROOTDIR)
163 solv_free((char *)dirpath);
165 if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
166 repodata_internalize(repo_last_repodata(repo));