2 * Copyright (c) 2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
22 #include "repo_cudf.h"
25 parseonedep(Pool *pool, char *p)
27 char *n, *ne, *e, *ee;
31 while (*p == ' ' || *p == '\t' || *p == '\n')
35 if (!strcmp(p, "!true"))
37 if (!strcmp(p, "!false"))
38 return pool_str2id(pool, p, 1);
40 /* find end of name */
41 while (*p && *p != ' ' && *p != '\t' && *p != '\n' && *p != '|')
44 while (*p == ' ' || *p == '\t' || *p == '\n')
49 if (*p == '>' || *p == '<' || *p == '=' || *p == '!')
58 flags |= REL_LT | REL_GT | REL_EQ;
60 if (flags && *p == '=')
66 while (*p == ' ' || *p == '\t' || *p == '\n')
69 while (*p && *p != ' ' && *p != '\t' && *p != '\n' && *p != '|')
72 while (*p == ' ' || *p == '\t' || *p == '\n')
75 name = pool_strn2id(pool, n, ne - n, 1);
78 evr = pool_strn2id(pool, e, ee - e, 1);
79 name = pool_rel2id(pool, name, evr, flags, 1);
83 Id id = parseonedep(pool, p + 1);
85 name = pool_rel2id(pool, name, id, REL_OR, 1);
90 makedeps(Repo *repo, char *deps, unsigned int olddeps, Id marker)
92 Pool *pool = repo->pool;
96 while ((p = strchr(deps, ',')) != 0)
99 olddeps = makedeps(repo, deps, olddeps, marker);
103 id = parseonedep(pool, deps);
106 return repo_addid_dep(repo, olddeps, id, marker);
110 copydeps(Pool *pool, Repo *repo, Offset fromoff, Repo *fromrepo)
118 from = fromrepo->idarraydata + fromoff;
119 for (ida = from, cc = 0; *ida; ida++, cc++)
123 off = repo_reserve_ids(repo, 0, cc);
124 memcpy(repo->idarraydata + off, from, (cc + 1) * sizeof(Id));
125 repo->idarraysize += cc + 1;
130 copysolvabledata(Pool *pool, Solvable *s, Repo *repo)
132 Repo *srepo = s->repo;
135 s->provides = copydeps(pool, repo, s->provides, srepo);
136 s->requires = copydeps(pool, repo, s->requires, srepo);
137 s->conflicts = copydeps(pool, repo, s->conflicts, srepo);
138 s->obsoletes = copydeps(pool, repo, s->obsoletes, srepo);
139 s->recommends = copydeps(pool, repo, s->recommends, srepo);
140 s->suggests = copydeps(pool, repo, s->suggests, srepo);
141 s->supplements = copydeps(pool, repo, s->supplements, srepo);
142 s->enhances = copydeps(pool, repo, s->enhances, srepo);
145 #define KEEP_VERSION 1
146 #define KEEP_PACKAGE 2
147 #define KEEP_FEATURE 3
150 finishpackage(Pool *pool, Solvable *s, int keep, Queue *job)
159 sid = pool_rel2id(pool, s->name, s->evr, REL_EQ, 1);
160 s->provides = repo_addid_dep(s->repo, s->provides, sid, 0);
161 if (!job || !pool->installed || s->repo != pool->installed)
163 if (keep == KEEP_VERSION)
164 queue_push2(job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME, sid);
165 else if (keep == KEEP_PACKAGE)
166 queue_push2(job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME, s->name);
167 else if (keep == KEEP_FEATURE)
169 for (idp = s->repo->idarraydata + s->provides; (id = *idp) != 0; idp++)
171 if (id != sid) /* skip self-provides */
172 queue_push2(job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, id);
178 repo_add_cudf(Repo *repo, Repo *installedrepo, FILE *fp, Queue *job, int flags)
190 xrepo = repo ? repo : installedrepo;
195 buf = solv_malloc(4096);
200 while (fgets(buf + bufl, bufa - bufl, fp) > 0)
202 bufl += strlen(buf + bufl);
203 if (bufl && buf[bufl - 1] != '\n')
205 if (bufa - bufl < 256)
208 buf = solv_realloc(buf, bufa);
214 if (c == ' ' || c == '\t')
216 /* continuation line */
227 if (s && !repo && !isinstalled)
229 repo_free_solvable(repo, s - pool->solvables, 1);
233 finishpackage(pool, s, keep, job);
240 p = strchr(buf, ':');
244 while (*p == ' ' || *p == '\t')
250 if (!strcmp(buf, "request"))
255 if (!strcmp(buf, "package"))
257 s = pool_id2solvable(pool, repo_add_solvable(xrepo));
266 if (!strcmp(buf, "install"))
269 Offset off = makedeps(xrepo, p, 0, 0);
270 for (idp = xrepo->idarraydata + off; (id = *idp) != 0; idp++)
271 queue_push2(job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, id);
273 else if (!strcmp(buf, "remove"))
276 Offset off = makedeps(xrepo, p, 0, 0);
277 for (idp = xrepo->idarraydata + off; (id = *idp) != 0; idp++)
278 queue_push2(job, SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES, id);
280 else if (!strcmp(buf, "upgrade"))
283 Offset off = makedeps(xrepo, p, 0, 0);
284 for (idp = xrepo->idarraydata + off; (id = *idp) != 0; idp++)
285 queue_push2(job, SOLVER_INSTALL|SOLVER_ORUPDATE|SOLVER_SOLVABLE_PROVIDES, id);
290 continue; /* we ignore the preamble for now */
294 if (!strcmp(buf, "conflicts"))
296 s->conflicts = makedeps(s->repo, p, s->conflicts, 0);
300 if (!strcmp(buf, "depends"))
302 s->requires = makedeps(s->repo, p, s->requires, 0);
307 if (!strcmp(buf, "keep"))
311 if (!strcmp(p, "version"))
313 else if (!strcmp(p, "package"))
315 else if (!strcmp(p, "feature"))
321 if (!strcmp(buf, "installed"))
323 if (!strcmp(p, "true"))
328 repo_free_solvable(repo, s - pool->solvables, 1);
331 else if (s->repo != installedrepo)
333 copysolvabledata(pool, s, installedrepo);
334 s->repo->nsolvables--;
335 s->repo = installedrepo;
336 if (s - pool->solvables < s->repo->start)
337 s->repo->start = s - pool->solvables;
338 if (s - pool->solvables >= s->repo->end)
339 s->repo->end = s - pool->solvables + 1;
340 s->repo->nsolvables++;
347 if (!strcmp(buf, "package"))
349 s->name = pool_str2id(pool, p, 1);
352 if (!strcmp(buf, "provides"))
354 s->provides = makedeps(s->repo, p, s->provides, 0);
359 if (!strcmp(buf, "depends"))
361 s->recommends = makedeps(s->repo, p, s->recommends, 0);
366 if (!strcmp(buf, "version"))
368 s->evr = pool_str2id(pool, p, 1);
374 if (s && !repo && !isinstalled)
376 repo_free_solvable(repo, s - pool->solvables, 1);
380 finishpackage(pool, s, keep, job);