- *r = 0;
- limitrelation(pool, job, REL_ARCH, archid);
- limitrelation(pool, job, flags, pool_str2id(pool, evr, 1));
- *r = '.';
- }
- else
- limitrelation(pool, job, flags, pool_str2id(pool, evr, 1));
- return job->count / 2;
-}
-
-int
-limitrepo(Pool *pool, Id repofilter, Queue *job)
-{
- Queue mq;
- Id p, pp;
- int i, j;
- Solvable *s;
-
- queue_init(&mq);
- for (i = j = 0; i < job->count; i += 2)
- {
- queue_empty(&mq);
- FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
- {
- s = pool_id2solvable(pool, p);
- if (s->repo && s->repo->repoid == repofilter)
- queue_push(&mq, p);
- }
- if (mq.count)
- {
- /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
- Id flags = (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
- if ((job->elements[i] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_NAME)
- flags |= SOLVER_SETNAME;
- if (mq.count == 1)
- {
- job->elements[j] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET | flags;
- job->elements[j + 1] = mq.elements[0];
- }
- else
- {
- job->elements[j] = SOLVER_SOLVABLE_ONE_OF | flags;
- job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
- }
- j += 2;
- }
- }
- queue_truncate(job, j);
- queue_free(&mq);
- return j / 2;
-}
-
-int
-mkselect(Pool *pool, int mode, char *name, Queue *job)
-{
- char *r, *r2;
- Id archid;
-
- if (*name == '/')
- {
- Dataiterator di;
- int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
- Queue q;
- queue_init(&q);
- dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
- while (dataiterator_step(&di))
- {
- Solvable *s = pool->solvables + di.solvid;
- if (!s->repo || !pool_installable(pool, s))
- continue;
- queue_push(&q, di.solvid);
- dataiterator_skip_solvable(&di);
- }
- dataiterator_free(&di);
- if (q.count)
- {
- printf("[using file list match for '%s']\n", name);
- if (q.count > 1)
- queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
- else
- queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
- queue_free(&q);
- return job->count / 2;
- }
- }
- if ((r = strpbrk(name, "<=>")) != 0)
- {
- /* relation case, support:
- * depglob rel
- * depglob.arch rel
- */
- int rflags = 0;
- int nend = r - name;
- char oldnend;
- for (; *r; r++)
- {
- if (*r == '<')
- rflags |= REL_LT;
- else if (*r == '=')
- rflags |= REL_EQ;
- else if (*r == '>')
- rflags |= REL_GT;
- else
- break;
- }
- while (*r && *r == ' ' && *r == '\t')
- r++;
- while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
- nend--;
- if (!*name || !*r)
- {
- fprintf(stderr, "bad relation\n");
- exit(1);
- }
- oldnend = name[nend];
- name[nend] = 0;
- if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
- {
- name[nend] = oldnend;
- limitrelation(pool, job, rflags, pool_str2id(pool, r, 1));
- return job->count / 2;
- }
- if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
- {
- *r2 = 0;
- if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
- {
- name[nend] = oldnend;
- *r2 = '.';
- limitrelation(pool, job, REL_ARCH, archid);
- limitrelation(pool, job, rflags, pool_str2id(pool, r, 1));
- return job->count / 2;
- }
- *r2 = '.';
- }
- name[nend] = oldnend;
- }
- else
- {
- /* no relation case, support:
- * depglob
- * depglob.arch
- * nameglob-version
- * nameglob-version.arch
- * nameglob-version-release
- * nameglob-version-release.arch
- */
- if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
- return job->count / 2;
- if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
- {
- *r = 0;
- if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
- {
- *r = '.';
- limitrelation(pool, job, REL_ARCH, archid);
- return job->count / 2;
- }
- *r = '.';
- }
- if ((r = strrchr(name, '-')) != 0)
- {
- *r = 0;
- if (depglob(pool, name, job, DEPGLOB_NAME))
- {
- /* have just the version */
- limitrelation_arch(pool, job, REL_EQ, r + 1);
- *r = '-';
- return job->count / 2;
- }
- if ((r2 = strrchr(name, '-')) != 0)
- {
- *r = '-';
- *r2 = 0;
- r = r2;
- if (depglob(pool, name, job, DEPGLOB_NAME))
- {
- /* have version-release */
- limitrelation_arch(pool, job, REL_EQ, r + 1);
- *r = '-';
- return job->count / 2;
- }
- }
- *r = '-';
- }
- }
- return 0;
-}
-
-
-int
-yesno(const char *str)
-{
- char inbuf[128], *ip;
-
- for (;;)
- {
- printf("%s", str);
- fflush(stdout);
- *inbuf = 0;
- if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
- {
- printf("Abort.\n");
- exit(1);
- }
- while (*ip == ' ' || *ip == '\t')
- ip++;
- if (*ip == 'q')
- {
- printf("Abort.\n");
- exit(1);
- }
- if (*ip == 'y' || *ip == 'n')
- return *ip == 'y' ? 1 : 0;
- }
-}
-
-#if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
-
-struct fcstate {
- FILE **newpkgsfps;
- Queue *checkq;
- int newpkgscnt;
- void *rpmdbstate;
-};
-
-static void *
-fileconflict_cb(Pool *pool, Id p, void *cbdata)
-{
- struct fcstate *fcstate = cbdata;
- Solvable *s;
- Id rpmdbid;
- int i;
- FILE *fp;
-
- if (!p)
- {
- rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
- return 0;
- }
- s = pool_id2solvable(pool, p);
- if (pool->installed && s->repo == pool->installed)
- {
- if (!s->repo->rpmdbid)
- return 0;
- rpmdbid = s->repo->rpmdbid[p - s->repo->start];
- if (!rpmdbid)
- return 0;
- return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
- }
- for (i = 0; i < fcstate->newpkgscnt; i++)
- if (fcstate->checkq->elements[i] == p)
- break;
- if (i == fcstate->newpkgscnt)
- return 0;
- fp = fcstate->newpkgsfps[i];
- if (!fp)
- return 0;
- rewind(fp);
- return rpm_byfp(fp, pool_solvable2str(pool, s), &fcstate->rpmdbstate);
-}
-
-
-void
-runrpm(const char *arg, const char *name, int dupfd3)
-{
- pid_t pid;
- int status;
-
- if ((pid = fork()) == (pid_t)-1)
- {
- perror("fork");
- exit(1);
- }
- if (pid == 0)
- {
- if (dupfd3 != -1 && dupfd3 != 3)
- {
- dup2(dupfd3, 3);
- close(dupfd3);
- }
- if (dupfd3 != -1)
- fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
- if (strcmp(arg, "-e") == 0)
- execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
- else
- execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
- perror("rpm");
- _exit(0);
- }
- while (waitpid(pid, &status, 0) != pid)
- ;
- if (status)
- {
- printf("rpm failed\n");
- exit(1);