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
33 add_releasefile_product(Repo *repo, FILE *fp)
35 Pool *pool = repo->pool;
40 int lnum = 0; /* line number */
43 /* parse /etc/<xyz>-release file */
44 while (fgets(buf, sizeof(buf), fp))
46 /* remove trailing \n */
48 if (l && buf[l - 1] == '\n')
54 /* 1st line, <name> [(<arch>)] */
55 ptr = strchr(buf, '(');
64 /* track back until non-blank, non-digit */
66 && (*ptr1 == ' ' || isdigit(*ptr1) || *ptr1 == '.'))
69 name = str2id(pool, join2("product", ":", buf), 1);
74 char *ptr1 = strchr(ptr, ')');
83 *ptr1 = tolower(*ptr1);
86 arch = str2id(pool, ptr, 1);
90 else if (strncmp(buf, "VERSION", 7) == 0)
92 ptr = strchr(buf + 7, '=');
97 version = makeevr(pool, ptr);
103 Solvable *s = pool_id2solvable(pool, repo_add_solvable(repo));
105 s->evr = version ? version : ID_EMPTY;
106 s->arch = arch ? arch : ARCH_NOARCH;
107 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
108 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
114 repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags)
117 struct dirent *entry;
121 dir = opendir(dirpath);
125 while ((entry = readdir(dir)))
127 int len = strlen(entry->d_name);
128 if (len > 8 && !strcmp(entry->d_name + len - 8, "-release"))
130 /* skip /etc/lsb-release, thats not a product per-se */
131 if (strcmp(entry->d_name, "lsb-release") == 0)
133 fullpath = join2(dirpath, "/", entry->d_name);
134 if ((fp = fopen(fullpath, "r")) == 0)
139 add_releasefile_product(repo, fp);
145 if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
146 repodata_internalize(repo_last_repodata(repo));