#include "repo_rpmdb.h"
#include "pool_fileconflicts.h"
#endif
+#ifdef ENABLE_PUBKEY
+#include "repo_pubkey.h"
+#endif
#ifdef ENABLE_DEBIAN
#include "repo_deb.h"
#endif
#include "repo_updateinfoxml.h"
#include "repo_deltainfoxml.h"
#endif
+#ifdef ENABLE_APPDATA
+#include "repo_appdata.h"
+#endif
#ifdef ENABLE_SUSEREPO
#include "repo_products.h"
#include "repo_susetags.h"
#include "repo_content.h"
#endif
+#ifdef SUSE
+#include "repo_autopattern.h"
+#endif
#include "solv_xfopen.h"
#ifdef FEDORA
# define PRODUCTS_PATH "/etc/products.d"
# define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
#endif
+#ifdef ENABLE_APPDATA
+# define APPDATA_PATH "/usr/share/appdata"
+#endif
#define SOLVCACHE_PATH "/var/cache/solv"
Queue q;
queue_init(&q);
- rpmstate = rpm_state_create(pool_get_rootdir(pool));
+ rpmstate = rpm_state_create(pool, pool_get_rootdir(pool));
rpm_installedrpmdbids(rpmstate, "Providename", "redhat-release", &q);
if (q.count)
{
{
char buf[1024];
const unsigned char *sum;
- void *h;
+ Chksum *h;
int l;
h = solv_chksum_create(chksumtype);
lseek(fileno(fp), 0, SEEK_SET);
possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
lseek(fileno(sigfp), 0, SEEK_SET);
- snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
+ snprintf(cmd, sizeof(cmd), "gpgv -q --homedir %s --keyring %s/pubring.gpg /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, gpgdir, fileno(sigfp), fileno(fp));
fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
r = system(cmd);
read_sigs()
{
Pool *sigpool = pool_create();
-#if defined(ENABLE_RPMDB_PUBKEY)
- Repo *repo = repo_create(sigpool, "rpmdbkeys");
+#if defined(ENABLE_PUBKEY) && defined(ENABLE_RPMDB)
+ Repo *repo = repo_create(sigpool, "pubkeys");
repo_add_rpmdb_pubkeys(repo, 0);
#endif
return sigpool;
calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
{
char buf[4096];
- void *h = solv_chksum_create(chktype);
+ Chksum *h = solv_chksum_create(chktype);
int l;
solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
void
calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
{
- void *h = solv_chksum_create(chktype);
+ Chksum *h = solv_chksum_create(chktype);
solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
if (cookie)
solv_chksum_add(h, cookie, 32);
pool_setarch(pool, un.machine);
}
+char *userhome;
+
char *
-calccachepath(Repo *repo, const char *repoext)
+calccachepath(Repo *repo, const char *repoext, int forcesystemloc)
{
- char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
+ char *q, *p;
+ int l;
+ if (!forcesystemloc && userhome && getuid())
+ p = pool_tmpjoin(repo->pool, userhome, "/.solvcache/", 0);
+ else
+ p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", 0);
+ l = strlen(p);
+ p = pool_tmpappend(repo->pool, p, repo->name, 0);
if (repoext)
{
p = pool_tmpappend(repo->pool, p, "_", repoext);
}
else
p = pool_tmpappend(repo->pool, p, ".solv", 0);
- q = p + strlen(SOLVCACHE_PATH) + 1;
+ q = p + l;
if (*q == '.')
*q = '_';
for (; *q; q++)
unsigned char myextcookie[32];
struct repoinfo *cinfo;
int flags;
+ int forcesystemloc;
+ forcesystemloc = mark & 2 ? 0 : 1;
+ if (mark < 2 && userhome && getuid())
+ {
+ /* first try home location */
+ int res = usecachedrepo(repo, repoext, cookie, mark | 2);
+ if (res)
+ return res;
+ }
+ mark &= 1;
cinfo = repo->appdata;
- if (!(fp = fopen(calccachepath(repo, repoext), "r")))
+ if (!(fp = fopen(calccachepath(repo, repoext, forcesystemloc), "r")))
return 0;
if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
{
{
FILE *fp;
int i, fd;
- char *tmpl;
+ char *tmpl, *cachedir;
struct repoinfo *cinfo;
int onepiece;
cinfo = repo->appdata;
if (cinfo && cinfo->incomplete)
return;
- mkdir(SOLVCACHE_PATH, 0755);
+ cachedir = userhome && getuid() ? pool_tmpjoin(repo->pool, userhome, "/.solvcache", 0) : SOLVCACHE_PATH;
+ if (access(cachedir, W_OK | X_OK) != 0 && mkdir(cachedir, 0755) == 0)
+ printf("[created %s]\n", cachedir);
/* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
- tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
+ tmpl = solv_dupjoin(cachedir, "/", ".newsolv-XXXXXX");
fd = mkstemp(tmpl);
if (fd < 0)
{
fclose(fp);
}
}
- if (!rename(tmpl, calccachepath(repo, repoext)))
+ if (!rename(tmpl, calccachepath(repo, repoext, 0)))
unlink(tmpl);
free(tmpl);
}
else
{
#if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
- FILE *ofp;
- Repo *ref = 0;
+ FILE *ofp = 0;
#endif
printf(" reading\n");
#if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
# if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
- if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
+ if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
{
fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
exit(1);
}
# endif
- if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
+# if defined(ENABLE_APPDATA)
+ if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
{
- ref = repo_create(pool, "@System.old");
- if (repo_add_solv(ref, ofp, 0))
- {
- repo_free(ref, 1);
- ref = 0;
- }
- fclose(ofp);
+ fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool));
+ exit(1);
}
- if (repo_add_rpmdb(repo, ref, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
+# endif
+ ofp = fopen(calccachepath(repo, 0, 0), "r");
+ if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
{
fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
exit(1);
}
- if (ref)
- repo_free(ref, 1);
+ if (ofp)
+ fclose(ofp);
#endif
#if defined(ENABLE_DEBIAN) && defined(DEBIAN)
- if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
+ if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
{
fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
exit(1);
}
#endif
+ repo_internalize(repo);
writecachedrepo(repo, 0, 0, installedcookie);
}
pool_set_installed(pool, repo);
repo->priority = 99 - cinfo->priority;
dorefresh = cinfo->autorefresh;
- if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
+ if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0, 0), &stb) == 0)
{
if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
dorefresh = 0;
fclose(fp);
}
+#ifdef ENABLE_APPDATA
+ filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
+ if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
+ {
+ if (repo_add_appdata(repo, fp, 0))
+ {
+ printf("appdata: %s\n", pool_errstr(pool));
+ cinfo->incomplete = 1;
+ }
+ fclose(fp);
+ }
+#endif
data = repo_add_repodata(repo, 0);
if (!repomd_add_ext(repo, data, "deltainfo"))
repomd_add_ext(repo, data, "prestodelta");
fclose(fp);
}
}
+#ifdef ENABLE_APPDATA
+ filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
+ if (!filename)
+ filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
+ if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
+ {
+ if (repo_add_appdata(repo, fp, 0))
+ {
+ printf("appdata: %s\n", pool_errstr(pool));
+ cinfo->incomplete = 1;
+ }
+ fclose(fp);
+ }
+#endif
repo_internalize(repo);
data = repo_add_repodata(repo, 0);
susetags_add_ext(repo, data);
rpmdbid = s->repo->rpmdbid[p - s->repo->start];
if (!rpmdbid)
return 0;
- return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
+ return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
}
for (i = 0; i < fcstate->newpkgscnt; i++)
if (fcstate->checkq->elements[i] == p)
static Id
nscallback(Pool *pool, void *data, Id name, Id evr)
{
- if (name == NAMESPACE_PRODUCTBUDDY)
- {
- /* SUSE specific hack: each product has an associated rpm */
- Solvable *s = pool->solvables + evr;
- Id p, pp, cap;
- Id bestp = 0;
-
- cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
- if (!cap)
- return 0;
- cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
- if (!cap)
- return 0;
- FOR_PROVIDES(p, pp, cap)
- {
- Solvable *ps = pool->solvables + p;
- if (ps->repo == s->repo && ps->arch == s->arch)
- if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
- bestp = p;
- }
- return bestp;
- }
#if 0
if (name == NAMESPACE_LANGUAGE)
{
if (repo->nrepodata < 2)
continue;
cinfo = repo->appdata;
+ if (repo != pool->installed && !cinfo)
+ continue;
if (cinfo && cinfo->incomplete)
continue;
data = repo_id2repodata(repo, 1);
#endif
+#ifdef SUSE
+static void
+add_autopackages(Pool *pool)
+{
+ int i;
+ Repo *repo;
+ FOR_REPOS(i, repo)
+ repo_add_autopattern(repo, 0);
+}
+#endif
+
#if defined(SUSE) || defined(FEDORA)
static void
add_patchjobs(Pool *pool, Queue *job)
Transaction *trans;
FILE **newpkgsfps;
Queue repofilter;
+ Queue kindfilter;
+ Queue archfilter;
+ int archfilter_src = 0;
int cleandeps = 0;
int forcebest = 0;
char *rootdir = 0;
+ char *keyname = 0;
+ int debuglevel = 0;
argc--;
argv++;
+ userhome = getenv("HOME");
+ if (userhome && userhome[0] != '/')
+ userhome = 0;
+ while (argc && !strcmp(argv[0], "-d"))
+ {
+ debuglevel++;
+ argc--;
+ argv++;
+ }
if (!argv[0])
usage(1);
if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
mainmode = MODE_ERASE;
mode = SOLVER_ERASE;
}
- else if (!strcmp(argv[0], "list"))
+ else if (!strcmp(argv[0], "list") || !strcmp(argv[0], "ls"))
{
mainmode = MODE_LIST;
mode = 0;
argc -= 2;
argv += 2;
}
-
else if (argc > 1 && !strcmp(argv[1], "--clean"))
{
cleandeps = 1;
argc--;
argv++;
}
+ if (argc > 2 && !strcmp(argv[1], "--keyname"))
+ {
+ keyname = argv[2];
+ argc -= 2;
+ argv += 2;
+ }
else
break;
}
#ifdef SUSE
pool->nscallback = nscallback;
#endif
- // pool_setdebuglevel(pool, 2);
+ if (debuglevel)
+ pool_setdebuglevel(pool, debuglevel);
setarch(pool);
+ pool_set_flag(pool, POOL_FLAG_ADDFILEPROVIDESFILTERED, 1);
repoinfos = read_repoinfos(pool, &nrepoinfos);
if (mainmode == MODE_REPOLIST)
read_repos(pool, repoinfos, nrepoinfos);
- /* setup repofilter */
+ /* setup filters */
queue_init(&repofilter);
- while (argc > 2 && !strcmp(argv[1], "-r"))
+ queue_init(&kindfilter);
+ queue_init(&archfilter);
+ while (argc > 1)
{
- const char *rname = argv[2], *rp;
- Id repoid = 0;
- for (rp = rname; *rp; rp++)
- if (*rp <= '0' || *rp >= '9')
- break;
- if (!*rp)
+ if (!strcmp(argv[1], "-i"))
{
- /* repo specified by number */
- int rnum = atoi(rname);
- for (i = 0; i < nrepoinfos; i++)
- {
- struct repoinfo *cinfo = repoinfos + i;
- if (!cinfo->enabled)
- continue;
- if (--rnum == 0)
- repoid = cinfo->repo->repoid;
- }
+ queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO, pool->installed->repoid);
+ argc--;
+ argv++;
}
- else
+ else if (argc > 2 && (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo")))
{
- /* repo specified by alias */
- Repo *repo;
- FOR_REPOS(i, repo)
+ const char *rname = argv[2], *rp;
+ Id repoid = 0;
+ for (rp = rname; *rp; rp++)
+ if (*rp <= '0' || *rp >= '9')
+ break;
+ if (!*rp)
+ {
+ /* repo specified by number */
+ int rnum = atoi(rname);
+ for (i = 0; i < nrepoinfos; i++)
+ {
+ struct repoinfo *cinfo = repoinfos + i;
+ if (!cinfo->enabled)
+ continue;
+ if (--rnum == 0)
+ repoid = cinfo->repo->repoid;
+ }
+ }
+ else
{
- if (!strcasecmp(rname, repo->name))
- repoid = repo->repoid;
+ /* repo specified by alias */
+ Repo *repo;
+ FOR_REPOS(i, repo)
+ {
+ if (!strcasecmp(rname, repo->name))
+ repoid = repo->repoid;
+ }
+ }
+ if (!repoid)
+ {
+ fprintf(stderr, "%s: no such repo\n", rname);
+ exit(1);
}
+ /* SETVENDOR is actually wrong but useful */
+ queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
+ argc -= 2;
+ argv += 2;
}
- if (!repoid)
+ else if (argc > 2 && !strcmp(argv[1], "--arch"))
{
- fprintf(stderr, "%s: no such repo\n", rname);
- exit(1);
+ if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc"))
+ archfilter_src = 1;
+ queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, argv[2], 1), REL_ARCH, 1));
+ argc -= 2;
+ argv += 2;
}
- /* SETVENDOR is actually wrong but useful */
- queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
- argc -= 2;
- argv += 2;
+ else if (argc > 2 && (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type")))
+ {
+ const char *kind = argv[2];
+ if (!strcmp(kind, "srcpackage"))
+ {
+ /* hey! should use --arch! */
+ queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, ARCH_SRC, REL_ARCH, 1));
+ archfilter_src = 1;
+ argc -= 2;
+ argv += 2;
+ continue;
+ }
+ if (!strcmp(kind, "package"))
+ kind = "";
+ if (!strcmp(kind, "all"))
+ queue_push2(&kindfilter, SOLVER_SOLVABLE_ALL, 0);
+ else
+ queue_push2(&kindfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, kind, 1), REL_KIND, 1));
+ argc -= 2;
+ argv += 2;
+ }
+ else
+ break;
}
if (mainmode == MODE_SEARCH)
}
/* process command line packages */
- if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
+ if (mainmode == MODE_LIST || mainmode == MODE_INFO || mainmode == MODE_INSTALL)
{
for (i = 1; i < argc; i++)
{
// printf("%s: %d solvables\n", repo->name, repo->nsolvables);
#if defined(ENABLE_RPMDB)
- addfileprovides(pool);
+ if (pool->disttype == DISTTYPE_RPM)
+ addfileprovides(pool);
+#endif
+#ifdef SUSE
+ add_autopackages(pool);
#endif
pool_createwhatprovides(pool);
+ if (keyname)
+ keyname = solv_dupjoin("solvable:", keyname, 0);
queue_init(&job);
for (i = 1; i < argc; i++)
{
queue_init(&job2);
flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
- if (mode == MODE_LIST)
+ if (kindfilter.count)
+ flags |= SELECTION_SKIP_KIND;
+ if (mode == MODE_LIST || archfilter_src)
flags |= SELECTION_WITH_SOURCE;
if (argv[i][0] == '/')
flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
- rflags = selection_make(pool, &job2, argv[i], flags);
+ if (!keyname)
+ rflags = selection_make(pool, &job2, argv[i], flags);
+ else
+ rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
if (repofilter.count)
selection_filter(pool, &job2, &repofilter);
+ if (archfilter.count)
+ selection_filter(pool, &job2, &archfilter);
+ if (kindfilter.count)
+ selection_filter(pool, &job2, &kindfilter);
if (!job2.count)
{
flags |= SELECTION_NOCASE;
- rflags = selection_make(pool, &job2, argv[i], flags);
+ if (!keyname)
+ rflags = selection_make(pool, &job2, argv[i], flags);
+ else
+ rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
if (repofilter.count)
selection_filter(pool, &job2, &repofilter);
+ if (archfilter.count)
+ selection_filter(pool, &job2, &archfilter);
+ if (kindfilter.count)
+ selection_filter(pool, &job2, &kindfilter);
if (job2.count)
printf("[ignoring case for '%s']\n", argv[i]);
}
queue_push(&job, job2.elements[j]);
queue_free(&job2);
}
+ keyname = solv_free(keyname);
- if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count))
+ if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count || archfilter.count || kindfilter.count))
{
queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
if (repofilter.count)
selection_filter(pool, &job, &repofilter);
+ if (archfilter.count)
+ selection_filter(pool, &job, &archfilter);
+ if (kindfilter.count)
+ selection_filter(pool, &job, &kindfilter);
}
queue_free(&repofilter);
+ queue_free(&archfilter);
+ queue_free(&kindfilter);
if (!job.count && mainmode != MODE_PATCH)
{
str = solvable_lookup_str(s, SOLVABLE_LICENSE);
if (str)
printf("License: %s\n", str);
+#if 0
+ str = solvable_lookup_sourcepkg(s);
+ if (str)
+ printf("Source: %s\n", str);
+#endif
printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
printf("\n");
}
if (s->repo == commandlinerepo)
{
loc = solvable_lookup_location(s, &medianr);
+ if (!loc)
+ continue;
if (!(newpkgsfps[i] = fopen(loc, "r")))
{
perror(loc);
printf("Searching for file conflicts\n");
queue_init(&conflicts);
- fcstate.rpmstate = rpm_state_create(rootdir);
+ fcstate.rpmstate = rpm_state_create(pool, rootdir);
fcstate.newpkgscnt = newpkgs;
fcstate.checkq = &checkq;
fcstate.newpkgsfps = newpkgsfps;
- pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
+ pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
if (conflicts.count)
{