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>
28 #include "tools_util.h"
29 #include "repo_releasefile_products.h"
31 #define BUFF_SIZE 8192
39 add_releasefile_product(struct parsedata *pd, FILE *fp)
41 Repo *repo = pd->repo;
42 Pool *pool = repo->pool;
47 int lnum = 0; /* line number */
50 /* parse /etc/<xyz>-release file */
51 while (fgets(buf, sizeof(buf), fp))
53 /* remove trailing \n */
55 if (l && buf[l - 1] == '\n')
61 /* 1st line, <name> [(<arch>)] */
62 ptr = strchr(buf, '(');
71 /* track back until non-blank, non-digit */
73 && (*ptr1 == ' ' || isdigit(*ptr1) || *ptr1 == '.'))
76 name = pool_str2id(pool, join2(&pd->jd, "product", ":", buf), 1);
81 char *ptr1 = strchr(ptr, ')');
90 *ptr1 = tolower(*ptr1);
93 arch = pool_str2id(pool, ptr, 1);
97 else if (strncmp(buf, "VERSION", 7) == 0)
99 ptr = strchr(buf + 7, '=');
102 while (*++ptr == ' ')
104 version = makeevr(pool, ptr);
110 Solvable *s = pool_id2solvable(pool, repo_add_solvable(repo));
112 s->evr = version ? version : ID_EMPTY;
113 s->arch = arch ? arch : ARCH_NOARCH;
114 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
115 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
121 repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
124 struct dirent *entry;
131 if (flags & REPO_USE_ROOTDIR)
132 dirpath = pool_prepend_rootdir(repo->pool, dirpath);
133 dir = opendir(dirpath);
136 if (flags & REPO_USE_ROOTDIR)
137 solv_free((char *)dirpath);
141 memset(&pd, 0, sizeof(pd));
143 while ((entry = readdir(dir)))
145 int len = strlen(entry->d_name);
146 if (len > 8 && !strcmp(entry->d_name + len - 8, "-release"))
148 /* skip /etc/lsb-release, thats not a product per-se */
149 if (strcmp(entry->d_name, "lsb-release") == 0)
151 fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
152 if ((fp = fopen(fullpath, "r")) == 0)
154 pool_error(repo->pool, 0, "%s: %s", fullpath, strerror(errno));
157 add_releasefile_product(&pd, fp);
162 join_freemem(&pd.jd);
163 if (flags & REPO_USE_ROOTDIR)
164 solv_free((char *)dirpath);
166 if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
167 repodata_internalize(repo_last_repodata(repo));