int rpmcliVerify(rpmts ts, QVA_t qva, const char ** argv) { rpmdepFlags depFlags = qva->depFlags, odepFlags; rpmtransFlags transFlags = qva->transFlags, otransFlags; rpmVSFlags vsflags, ovsflags; int ec = 0; #if defined(_OPENMP) (void) tagName(0); /* XXX instantiate the tagname store. */ omp_set_nested(1); /* XXX permit nested thread teams. */ #endif if (qva->qva_showPackage == NULL) qva->qva_showPackage = showVerifyPackage; /* XXX verify flags are inverted from query. */ vsflags = rpmExpandNumeric("%{?_vsflags_verify}"); if (!(qva->qva_flags & VERIFY_DIGEST)) vsflags |= _RPMVSF_NODIGESTS; if (!(qva->qva_flags & VERIFY_SIGNATURE)) vsflags |= _RPMVSF_NOSIGNATURES; if (!(qva->qva_flags & VERIFY_HDRCHK)) vsflags |= RPMVSF_NOHDRCHK; vsflags &= ~RPMVSF_NEEDPAYLOAD; odepFlags = rpmtsSetDFlags(ts, depFlags); otransFlags = rpmtsSetFlags(ts, transFlags); ovsflags = rpmtsSetVSFlags(ts, vsflags); ec = rpmcliArgIter(ts, qva, argv); vsflags = rpmtsSetVSFlags(ts, ovsflags); transFlags = rpmtsSetFlags(ts, otransFlags); depFlags = rpmtsSetDFlags(ts, odepFlags); if (qva->qva_showPackage == showVerifyPackage) qva->qva_showPackage = NULL; rpmtsEmpty(ts); return ec; }
int main(int argc, char *argv[]) { HE_t he = (HE_t)memset(alloca(sizeof(*he)), 0, sizeof(*he)); poptContext optCon; rpmts ts = NULL; rpmgi gi = NULL; size_t n = 4096; static double e = 1.0e-4; size_t m = 0; size_t k = 0; rpmTag gitag = RPMDBI_PACKAGES; rpmTag hetag = RPMTAG_DIRNAMES; ARGV_t av; rpmRC rc; int ec = EXIT_FAILURE; FD_t fd; struct stat sb; static const char fn_dirs[] = "/tmp/dirs.xz"; size_t ndirs = 0; size_t ndirb = 0; size_t ndirxz = 0; static const char fn_bf[] = "/tmp/bf.xz"; static const char fmode_w[] = "w9.xzdio"; rpmbf * bfa = NULL; size_t npkgs = 0; size_t nb = 0; size_t nover = 0; int ix = 0; int jx; int xx; optCon = rpmcliInit(argc, argv, optionsTable); if (optCon == NULL) goto exit; if (rpmioFtsOpts == 0) rpmioFtsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT); if (gitagstr != NULL) gitag = tagValue(gitagstr); av = poptGetArgs(optCon); ts = rpmtsCreate(); (void) rpmtsSetFlags(ts, transFlags); (void) rpmtsSetDFlags(ts, depFlags); (void) rpmtsSetVSFlags(ts, vsFlags); gi = rpmgiNew(ts, gitag, gikeystr, 0); (void) rpmgiSetArgs(gi, av, rpmioFtsOpts, giFlags); npkgs = 0; while ((rc = rpmgiNext(gi)) == RPMRC_OK) npkgs++; bfa = xcalloc(npkgs, sizeof(*bfa)); rpmbfParams(n, e, &m, &k); fd = Fopen(fn_dirs, fmode_w); nb = 0; ix = 0; while ((rc = rpmgiNext(gi)) == RPMRC_OK) { static const char newline[] = "\n"; rpmbf bf; Header h; bf = NULL; h = rpmgiHeader(gi); he->tag = hetag; if (headerGet(h, he, 0) && he->c > 0) { /* XXX make sure n >= _nmin in rpmbfParams() */ n = (he->c > 10 ? he->c : 10); rpmbfParams(n, e, &m, &k); nb += (m+7)/8; bf = rpmbfNew(m, k, 0); for (jx = 0; jx < (int) he->c; jx++) { const char * s = he->p.argv[jx]; size_t ns = strlen(s); xx = rpmbfAdd(bf, s, ns); xx = Fwrite(s, 1, ns, fd); xx = Fwrite(newline, 1, 1, fd); ndirs++; ndirb += ns + 1; } } xx = Fwrite(newline, 1, 1, fd); ndirb++; bfa[ix++] = bf; } xx = Fclose(fd); xx = Stat(fn_dirs, &sb); xx = Unlink(fn_dirs); ndirxz = sb.st_size; fprintf(stdout, " npkgs: %u\n", (unsigned) npkgs); fprintf(stdout, " Dirnames: %u bytes (%u items)\n", (unsigned) ndirb, ndirs); fprintf(stdout, " with XZDIO: %u bytes\n", (unsigned) ndirxz); fprintf(stdout, "Bloom filter: false positives: %5.2g\n", e); nover = npkgs * 16; fprintf(stdout, "Uncompressed: %u = parms(%u) + bitmaps(%u) bytes\n", (unsigned)nb+nover, (unsigned)nover, (unsigned)nb); fprintf(stdout, " with XZDIO: %u bytes\n", rpmbfWrite(Fopen(fn_bf, fmode_w), bfa, npkgs)); ec = EXIT_SUCCESS; exit: for (ix = 0; ix < (int) npkgs; ix++) bfa[ix] = rpmbfFree(bfa[ix]); bfa = _free(bfa); gi = rpmgiFree(gi); (void) rpmtsFree(ts); ts = NULL; optCon = rpmcliFini(optCon); return ec; }
static JSBool rpmts_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = (rpmts)ptr; jsint tiny = JSVAL_TO_INT(id); int myint; /* XXX the class has ptr == NULL, instances have ptr != NULL. */ if (ptr == NULL) return JS_TRUE; switch (tiny) { case _DEBUG: if (!JS_ValueToInt32(cx, *vp, &_debug)) break; break; case _VSFLAGS: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetVSFlags(ts, (rpmVSFlags)myint); break; case _TYPE: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetType(ts, (rpmTSType)myint); break; case _ARBGOAL: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetARBGoal(ts, (uint32_t)myint); break; case _ROOTDIR: (void) rpmtsSetRootDir(ts, JS_GetStringBytes(JS_ValueToString(cx, *vp))); break; case _CURRDIR: (void) rpmtsSetCurrDir(ts, JS_GetStringBytes(JS_ValueToString(cx, *vp))); break; case _CHROOTDONE: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetChrootDone(ts, myint); break; case _TID: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetTid(ts, (uint32_t)myint); break; case _FLAGS: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetFlags(ts, myint); break; case _DFLAGS: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetDFlags(ts, (rpmdepFlags)myint); break; case _GOAL: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetGoal(ts, (tsmStage)myint); break; case _DBMODE: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetDBMode(ts, myint); break; case _COLOR: if (!JS_ValueToInt32(cx, *vp, &myint)) break; (void) rpmtsSetColor(ts, (uint32_t)(myint & 0x0f)); break; default: break; } return JS_TRUE; }
rpmRC rpmgiNext(/*@null@*/ rpmgi gi) { char hnum[32]; rpmRC rpmrc = RPMRC_NOTFOUND; int xx; if (gi == NULL) return rpmrc; if (_rpmgi_debug) fprintf(stderr, "--> %s(%p) tag %s\n", __FUNCTION__, gi, tagName(gi->tag)); /* Free header from previous iteration. */ (void)headerFree(gi->h); gi->h = NULL; gi->hdrPath = _free(gi->hdrPath); hnum[0] = '\0'; if (++gi->i >= 0) switch (gi->tag) { default: if (!gi->active) { nextkey: rpmrc = rpmgiLoadNextKey(gi); if (rpmrc != RPMRC_OK) goto enditer; rpmrc = rpmgiInitFilter(gi); if (rpmrc != RPMRC_OK || gi->mi == NULL) { gi->mi = rpmmiFree(gi->mi); /* XXX unnecessary */ gi->i++; goto nextkey; } rpmrc = RPMRC_NOTFOUND; /* XXX hack */ gi->active = 1; } if (gi->mi != NULL) { /* XXX unnecessary */ Header h = rpmmiNext(gi->mi); if (h != NULL) { if (!(gi->flags & RPMGI_NOHEADER)) gi->h = headerLink(h); /* XXX use h->origin instead. */ sprintf(hnum, "%u", (unsigned)rpmmiInstance(gi->mi)); gi->hdrPath = rpmExpand("rpmdb h# ", hnum, NULL); rpmrc = RPMRC_OK; /* XXX header reference held by iterator, so no headerFree */ } } if (rpmrc != RPMRC_OK) { gi->mi = rpmmiFree(gi->mi); goto nextkey; } break; case RPMDBI_PACKAGES: if (!gi->active) { rpmrc = rpmgiInitFilter(gi); if (rpmrc != RPMRC_OK) { gi->mi = rpmmiFree(gi->mi); /* XXX unnecessary */ goto enditer; } rpmrc = RPMRC_NOTFOUND; /* XXX hack */ gi->active = 1; } if (gi->mi != NULL) { /* XXX unnecessary */ Header h = rpmmiNext(gi->mi); if (h != NULL) { if (!(gi->flags & RPMGI_NOHEADER)) gi->h = headerLink(h); /* XXX use h->origin instead. */ sprintf(hnum, "%u", (unsigned)rpmmiInstance(gi->mi)); gi->hdrPath = rpmExpand("rpmdb h# ", hnum, NULL); rpmrc = RPMRC_OK; /* XXX header reference held by iterator, so no headerFree */ } } if (rpmrc != RPMRC_OK) { gi->mi = rpmmiFree(gi->mi); goto enditer; } break; case RPMDBI_REMOVED: case RPMDBI_ADDED: { rpmte p; int teType = 0; const char * teTypeString = NULL; if (!gi->active) { gi->tsi = rpmtsiInit(gi->ts); gi->active = 1; } if ((p = rpmtsiNext(gi->tsi, teType)) != NULL) { Header h = rpmteHeader(p); if (h != NULL) if (!(gi->flags & RPMGI_NOHEADER)) { gi->h = headerLink(h); switch(rpmteType(p)) { case TR_ADDED: teTypeString = "+++"; /*@switchbreak@*/break; case TR_REMOVED: teTypeString = "---"; /*@switchbreak@*/break; } sprintf(hnum, "%u", (unsigned)gi->i); gi->hdrPath = rpmExpand("%s h# ", teTypeString, hnum, NULL); rpmrc = RPMRC_OK; (void)headerFree(h); h = NULL; } } if (rpmrc != RPMRC_OK) { gi->tsi = rpmtsiFree(gi->tsi); goto enditer; } } break; case RPMDBI_HDLIST: if (!gi->active) { const char * path = rpmExpand("%{?_query_hdlist_path}", NULL); if (path == NULL || *path == '\0') { path = _free(path); path = rpmExpand(_query_hdlist_path, NULL); } gi->fd = rpmgiOpen(path, "rm%{?_rpmgio}"); gi->active = 1; path = _free(path); } if (gi->fd != NULL) { Header h = NULL; const char item[] = "Header"; const char * msg = NULL; /*@+voidabstract@*/ rpmrc = rpmpkgRead(item, gi->fd, &h, &msg); /*@=voidabstract@*/ switch(rpmrc) { default: rpmlog(RPMLOG_ERR, "%s: %s: %s\n", "rpmpkgRead", item, msg); case RPMRC_NOTFOUND: h = NULL; case RPMRC_OK: break; } msg = _free(msg); if (h != NULL) { if (!(gi->flags & RPMGI_NOHEADER)) gi->h = headerLink(h); sprintf(hnum, "%u", (unsigned)gi->i); gi->hdrPath = rpmExpand("hdlist h# ", hnum, NULL); rpmrc = RPMRC_OK; (void)headerFree(h); h = NULL; } } if (rpmrc != RPMRC_OK) { if (gi->fd != NULL) (void) Fclose(gi->fd); gi->fd = NULL; goto enditer; } break; case RPMDBI_ARGLIST: /* XXX gi->active initialize? */ if (_rpmgi_debug < 0) fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]); /* Read next header, lazily expanding manifests as found. */ rpmrc = rpmgiLoadReadHeader(gi); if (rpmrc != RPMRC_OK) /* XXX check this */ goto enditer; gi->hdrPath = xstrdup(gi->argv[gi->i]); break; case RPMDBI_FTSWALK: if (gi->argv == NULL || gi->argv[0] == NULL) /* HACK */ goto enditer; if (!gi->active) { gi->ftsp = Fts_open((char *const *)gi->argv, gi->ftsOpts, NULL); /* XXX NULL with open(2)/malloc(3) errno set */ gi->active = 1; } /* Read next header, lazily walking file tree. */ rpmrc = rpmgiWalkReadHeader(gi); if (rpmrc != RPMRC_OK) { xx = Fts_close(gi->ftsp); gi->ftsp = NULL; goto enditer; } if (gi->fts != NULL) gi->hdrPath = xstrdup(gi->fts->fts_path); break; } if ((gi->flags & RPMGI_TSADD) && gi->h != NULL) { /* XXX rpmgi hack: Save header in transaction element. */ if (gi->flags & RPMGI_ERASING) { uint32_t hdrNum = headerGetInstance(gi->h); xx = rpmtsAddEraseElement(gi->ts, gi->h, hdrNum); } else xx = rpmtsAddInstallElement(gi->ts, gi->h, (fnpyKey)gi->hdrPath, 2, NULL); } goto exit; enditer: if (gi->flags & RPMGI_TSORDER) { rpmts ts = gi->ts; /* Block access to indices used for depsolving. */ if (!(gi->flags & RPMGI_ERASING)) { (void) rpmtsSetGoal(ts, TSM_INSTALL); xx = rpmdbBlockDBI(rpmtsGetRdb(ts), -RPMDBI_DEPCACHE); xx = rpmdbBlockDBI(rpmtsGetRdb(ts), -RPMTAG_BASENAMES); xx = rpmdbBlockDBI(rpmtsGetRdb(ts), -RPMTAG_PROVIDENAME); } else { (void) rpmtsSetGoal(ts, TSM_ERASE); } /* XXX query/verify will need the glop added to a buffer instead. */ xx = rpmcliInstallCheck(ts); xx = rpmcliInstallSuggests(ts); /* Permit access to indices used for depsolving. */ if (!(gi->flags & RPMGI_ERASING)) { xx = rpmdbBlockDBI(rpmtsGetRdb(ts), RPMTAG_PROVIDENAME); xx = rpmdbBlockDBI(rpmtsGetRdb(ts), RPMTAG_BASENAMES); xx = rpmdbBlockDBI(rpmtsGetRdb(ts), RPMDBI_DEPCACHE); } /* XXX Display dependency loops with rpm -qvT. */ if (rpmIsVerbose()) (void) rpmtsSetDFlags(ts, (rpmtsDFlags(ts) | RPMDEPS_FLAG_DEPLOOPS)); xx = (*gi->tsOrder) (ts); /* XXX hackery alert! */ gi->tag = (!(gi->flags & RPMGI_ERASING) ? RPMDBI_ADDED : RPMDBI_REMOVED); gi->flags &= ~(RPMGI_TSADD|RPMGI_TSORDER); } (void)headerFree(gi->h); gi->h = NULL; gi->hdrPath = _free(gi->hdrPath); gi->i = -1; gi->active = 0; exit: if (_rpmgi_debug) fprintf(stderr, "<-- %s(%p) rc %d\n", __FUNCTION__, gi, rpmrc); return rpmrc; }