/** * Check installed package dependencies for problems. * @param ts transaction set * @param h header * @return number of problems found (0 for no problems) */ static int verifyDependencies(rpmts ts, Header h) { rpmps ps; rpmte te; int rc; rpmtsEmpty(ts); (void) rpmtsAddInstallElement(ts, h, NULL, 0, NULL); (void) rpmtsCheck(ts); te = rpmtsElement(ts, 0); ps = rpmteProblems(te); rc = rpmpsNumProblems(ps); if (rc > 0) { rpmlog(RPMLOG_NOTICE, _("Unsatisfied dependencies for %s:\n"), rpmteNEVRA(te)); rpmpsi psi = rpmpsInitIterator(ps); rpmProblem p; while ((p = rpmpsiNext(psi)) != NULL) { char * ps = rpmProblemString(p); rpmlog(RPMLOG_NOTICE, "\t%s\n", ps); free(ps); } rpmpsFreeIterator(psi); } rpmpsFree(ps); rpmtsEmpty(ts); return rc; }
/** * Return exit code from running verify script from header. * @todo malloc/free/refcount handling is fishy here. * @param qva parsed query/verify options * @param ts transaction set * @param h header * @param scriptFd file handle to use for stderr (or NULL) * @return 0 on success */ static int rpmVerifyScript(QVA_t qva, rpmts ts, Header h, FD_t scriptFd) { rpmpsm psm = NULL; rpmte te = NULL; int rc = 0; /* fake up a erasure transaction element */ rc = rpmtsAddEraseElement(ts, h, -1); te = rpmtsElement(ts, 0); rpmteOpen(te, ts, 0); if (scriptFd != NULL) rpmtsSetScriptFd(ts, scriptFd); /* create psm to run the script */ psm = rpmpsmNew(ts, te); rpmpsmScriptStage(psm, RPMTAG_VERIFYSCRIPT, RPMTAG_VERIFYSCRIPTPROG); rc = rpmpsmStage(psm, PSM_SCRIPT); psm = rpmpsmFree(psm); if (scriptFd != NULL) rpmtsSetScriptFd(ts, NULL); /* clean up our fake transaction bits */ rpmteClose(te, ts, 0); rpmtsEmpty(ts); return rc; }
/** * @todo Create transaction set *much* earlier. */ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro) { rpmts ts = rpmtsCreate(); rpmfi fi = csa->cpioList; rpmte te = NULL; rpmfs fs = NULL; char *failedFile = NULL; FD_t cfd; rpmRC rc = RPMRC_OK; int xx, i; { char *fmode = rpmExpand(fmodeMacro, NULL); if (!(fmode && fmode[0] == 'w')) fmode = xstrdup("w9.gzdio"); (void) Fflush(fdo); cfd = Fdopen(fdDup(Fileno(fdo)), fmode); fmode = _free(fmode); } if (cfd == NULL) return RPMRC_FAIL; /* make up a transaction element for passing to fsm */ rpmtsAddInstallElement(ts, h, NULL, 0, NULL); te = rpmtsElement(ts, 0); fs = rpmteGetFileStates(te); fi = rpmfiInit(fi, 0); while ((i = rpmfiNext(fi)) >= 0) { if (rpmfiFFlags(fi) & RPMFILE_GHOST) rpmfsSetAction(fs, i, FA_SKIP); else rpmfsSetAction(fs, i, FA_COPYOUT); } xx = fsmSetup(rpmfiFSM(fi), FSM_PKGBUILD, ts, te, fi, cfd, &csa->cpioArchiveSize, &failedFile); if (xx) rc = RPMRC_FAIL; (void) Fclose(cfd); xx = fsmTeardown(rpmfiFSM(fi)); if (rc == RPMRC_OK && xx) rc = RPMRC_FAIL; if (rc) { if (failedFile) rpmlog(RPMLOG_ERR, _("create archive failed on file %s: %s\n"), failedFile, cpioStrerror(rc)); else rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"), cpioStrerror(rc)); rc = RPMRC_FAIL; } rpmtsEmpty(ts); failedFile = _free(failedFile); ts = rpmtsFree(ts); return rc; }
/** * Return next transaction element. * @param tsi transaction element iterator * @return transaction element, NULL on termination */ static rpmte rpmtsiNextElement(rpmtsi tsi) { rpmte te = NULL; int oc = -1; if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0) return te; if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++; if (oc != -1) te = rpmtsElement(tsi->ts, oc); return te; }
static JSBool rpmts_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; JSBool ok = JS_FALSE; int oc; _RESOLVE_DEBUG_ENTRY(_debug); if (flags & JSRESOLVE_ASSIGNING) { ok = JS_TRUE; goto exit; } if (JSVAL_IS_INT(id) && (oc = JSVAL_TO_INT(id)) >= 0 && oc < rpmtsNElements(ts)) { JSObject *teo = NULL; rpmte te = NULL; /* XXX rpmteLink/rpmteUnlink are no-ops */ if ((te = rpmtsElement(ts, oc)) == NULL || (teo = JS_NewObject(cx, &rpmteClass, NULL, NULL)) == NULL || !JS_SetPrivate(cx, teo, rpmteLink(te)) || !JS_DefineElement(cx, obj, oc, OBJECT_TO_JSVAL(teo), NULL, NULL, JSPROP_ENUMERATE)) { *objp = NULL; goto exit; } *objp = obj; } else *objp = NULL; ok = JS_TRUE; exit: return ok; }
rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd, char ** specFilePtr, char ** cookie) { Header h = NULL; rpmpsm psm = NULL; rpmte te = NULL; rpmRC rpmrc; int specix = -1; rpmrc = rpmReadPackageFile(ts, fd, NULL, &h); switch (rpmrc) { case RPMRC_NOTTRUSTED: case RPMRC_NOKEY: case RPMRC_OK: break; default: goto exit; break; } if (h == NULL) goto exit; rpmrc = RPMRC_FAIL; /* assume failure */ if (!headerIsSource(h)) { rpmlog(RPMLOG_ERR, _("source package expected, binary found\n")); goto exit; } /* src.rpm install can require specific rpmlib features, check them */ if (!rpmlibDeps(h)) goto exit; specix = headerFindSpec(h); if (specix < 0) { rpmlog(RPMLOG_ERR, _("source package contains no .spec file\n")); goto exit; }; if (rpmtsAddInstallElement(ts, h, NULL, 0, NULL)) { goto exit; } te = rpmtsElement(ts, 0); if (te == NULL) { /* XXX can't happen */ goto exit; } rpmteSetFd(te, fd); rpmteSetHeader(te, h); { /* set all files to be installed */ rpmfs fs = rpmteGetFileStates(te); int fc = rpmfsFC(fs); for (int i = 0; i < fc; i++) rpmfsSetAction(fs, i, FA_CREATE); } psm = rpmpsmNew(ts, te, PKG_INSTALL); if (rpmpsmUnpack(psm) == RPMRC_OK) rpmrc = RPMRC_OK; rpmpsmFree(psm); exit: if (rpmrc == RPMRC_OK && specix >= 0) { if (cookie) *cookie = headerGetAsString(h, RPMTAG_COOKIE); if (specFilePtr) { rpmfiles files = rpmteFiles(te); *specFilePtr = rpmfilesFN(files, specix); rpmfilesFree(files); } } /* XXX nuke the added package(s). */ headerFree(h); rpmtsEmpty(ts); return rpmrc; }
rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd, char ** specFilePtr, char ** cookie) { rpmfi fi = NULL; char * specFile = NULL; const char *rootdir = rpmtsRootDir(ts); Header h = NULL; rpmpsm psm = NULL; rpmte te = NULL; rpmRC rpmrc; int specix = -1; struct rpmtd_s filenames; rpmtdReset(&filenames); rpmrc = rpmReadPackageFile(ts, fd, NULL, &h); switch (rpmrc) { case RPMRC_NOTTRUSTED: case RPMRC_NOKEY: case RPMRC_OK: break; default: goto exit; break; } if (h == NULL) goto exit; rpmrc = RPMRC_FAIL; /* assume failure */ if (!headerIsSource(h)) { rpmlog(RPMLOG_ERR, _("source package expected, binary found\n")); goto exit; } /* src.rpm install can require specific rpmlib features, check them */ if (!rpmlibDeps(h)) goto exit; if (headerGet(h, RPMTAG_BASENAMES, &filenames, HEADERGET_ALLOC)) { struct rpmtd_s td; const char *str; const char *_cookie = headerGetString(h, RPMTAG_COOKIE); if (cookie && _cookie) *cookie = xstrdup(_cookie); /* Try to find spec by file flags */ if (_cookie && headerGet(h, RPMTAG_FILEFLAGS, &td, HEADERGET_MINMEM)) { rpmfileAttrs *flags; while (specix < 0 && (flags = rpmtdNextUint32(&td))) { if (*flags & RPMFILE_SPECFILE) specix = rpmtdGetIndex(&td); } } /* Still no spec? Look by filename. */ while (specix < 0 && (str = rpmtdNextString(&filenames))) { if (rpmFileHasSuffix(str, ".spec")) specix = rpmtdGetIndex(&filenames); } } if (rootdir && rstreq(rootdir, "/")) rootdir = NULL; /* Macros need to be added before trying to create directories */ rpmInstallLoadMacros(h); if (specix >= 0) { const char *bn; headerDel(h, RPMTAG_BASENAMES); headerDel(h, RPMTAG_DIRNAMES); headerDel(h, RPMTAG_DIRINDEXES); rpmtdInit(&filenames); for (int i = 0; (bn = rpmtdNextString(&filenames)); i++) { int spec = (i == specix); char *fn = rpmGenPath(rpmtsRootDir(ts), spec ? "%{_specdir}" : "%{_sourcedir}", bn); headerPutString(h, RPMTAG_OLDFILENAMES, fn); if (spec) specFile = xstrdup(fn); free(fn); } headerConvert(h, HEADERCONV_COMPRESSFILELIST); } else { rpmlog(RPMLOG_ERR, _("source package contains no .spec file\n")); goto exit; }; if (rpmtsAddInstallElement(ts, h, NULL, 0, NULL)) { goto exit; } te = rpmtsElement(ts, 0); if (te == NULL) { /* XXX can't happen */ goto exit; } rpmteSetFd(te, fd); rpmteSetHeader(te, h); fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER); h = headerFree(h); if (fi == NULL) { goto exit; } fi->apath = filenames.data; /* Ick */ rpmteSetFI(te, fi); fi = rpmfiFree(fi); if (rpmMkdirs(rpmtsRootDir(ts), "%{_topdir}:%{_sourcedir}:%{_specdir}")) { goto exit; } { /* set all files to be installed */ rpmfs fs = rpmteGetFileStates(te); int i; unsigned int fc = rpmfiFC(fi); for (i=0; i<fc; i++) rpmfsSetAction(fs, i, FA_CREATE); } psm = rpmpsmNew(ts, te); psm->goal = PKG_INSTALL; /* FIX: psm->fi->dnl should be owned. */ if (rpmpsmStage(psm, PSM_PROCESS) == RPMRC_OK) rpmrc = RPMRC_OK; (void) rpmpsmStage(psm, PSM_FINI); rpmpsmFree(psm); exit: if (specFilePtr && specFile && rpmrc == RPMRC_OK) *specFilePtr = specFile; else free(specFile); headerFree(h); rpmfiFree(fi); /* XXX nuke the added package(s). */ rpmtsClean(ts); return rpmrc; }
static JSBool rpmts_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; jsint tiny = JSVAL_TO_INT(id); _PROP_DEBUG_ENTRY(_debug < 0); /* XXX the class has ptr == NULL, instances have ptr != NULL. */ if (ptr == NULL) return JS_TRUE; switch (tiny) { case _DEBUG: *vp = INT_TO_JSVAL(_debug); break; case _LENGTH: *vp = INT_TO_JSVAL(rpmtsNElements(ts)); break; case _VSFLAGS: *vp = INT_TO_JSVAL((jsint)rpmtsVSFlags(ts)); break; case _TYPE: *vp = INT_TO_JSVAL((jsint)rpmtsType(ts)); break; case _ARBGOAL: *vp = INT_TO_JSVAL((jsint)rpmtsARBGoal(ts)); break; case _ROOTDIR: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, rpmtsRootDir(ts))); break; case _CURRDIR: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, rpmtsCurrDir(ts))); break; case _SELINUX: *vp = INT_TO_JSVAL((jsint)rpmtsSELinuxEnabled(ts)); break; case _CHROOTDONE: *vp = INT_TO_JSVAL((jsint)rpmtsChrootDone(ts)); break; case _TID: *vp = INT_TO_JSVAL((jsint)rpmtsGetTid(ts)); break; case _NELEMENTS: *vp = INT_TO_JSVAL((jsint)rpmtsNElements(ts)); break; case _PROBFILTER: *vp = INT_TO_JSVAL((jsint)rpmtsFilterFlags(ts)); break; case _FLAGS: *vp = INT_TO_JSVAL((jsint)rpmtsFlags(ts)); break; case _DFLAGS: *vp = INT_TO_JSVAL((jsint)rpmtsDFlags(ts)); break; case _GOAL: *vp = INT_TO_JSVAL((jsint)rpmtsGoal(ts)); break; case _DBMODE: *vp = INT_TO_JSVAL((jsint)rpmtsDBMode(ts)); break; case _COLOR: *vp = INT_TO_JSVAL((jsint)rpmtsColor(ts)); break; case _PREFCOLOR: *vp = INT_TO_JSVAL((jsint)rpmtsPrefColor(ts)); break; default: if (JSVAL_IS_INT(id)) { int oc = JSVAL_TO_INT(id); JSObject *teo = NULL; rpmte te = NULL; /* XXX rpmteLink/rpmteUnlink are no-ops */ if ((te = rpmtsElement(ts, oc)) != NULL && (teo = JS_NewObject(cx, &rpmteClass, NULL, NULL)) != NULL && JS_SetPrivate(cx, teo, rpmteLink(te))) { *vp = OBJECT_TO_JSVAL(teo); } break; } #ifdef DYING if (JSVAL_IS_STRING(id)) { JSString * str = JS_ValueToString(cx, id); const char * name = JS_GetStringBytes(str); if (!strcmp(name, "NVRA")) { JSObject * NVRA = rpmtsLoadNVRA(cx, obj); *vp = OBJECT_TO_JSVAL(NVRA); } break; } #endif break; } return JS_TRUE; }