/** * 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; }
/* * For packages being installed: * - verify package arch/os. * - verify package epoch:version-release is newer. */ static rpmps checkProblems(rpmts ts) { rpm_color_t tscolor = rpmtsColor(ts); rpmprobFilterFlags probFilter = rpmtsFilterFlags(ts); rpmstrPool tspool = rpmtsPool(ts); rpmtsi pi = rpmtsiInit(ts); rpmte p; /* The ordering doesn't matter here */ /* XXX Only added packages need be checked. */ rpmlog(RPMLOG_DEBUG, "sanity checking %d elements\n", rpmtsNElements(ts)); while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) { if (!(probFilter & RPMPROB_FILTER_IGNOREARCH) && badArch(rpmteA(p))) rpmteAddProblem(p, RPMPROB_BADARCH, rpmteA(p), NULL, 0); if (!(probFilter & RPMPROB_FILTER_IGNOREOS) && badOs(rpmteO(p))) rpmteAddProblem(p, RPMPROB_BADOS, rpmteO(p), NULL, 0); if (!(probFilter & RPMPROB_FILTER_OLDPACKAGE)) { Header h; rpmdbMatchIterator mi; mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0); while ((h = rpmdbNextIterator(mi)) != NULL) ensureOlder(tspool, p, h); rpmdbFreeIterator(mi); } if (!(probFilter & RPMPROB_FILTER_REPLACEPKG)) { Header h; rpmdbMatchIterator mi; mi = rpmtsPrunedIterator(ts, RPMDBI_NAME, rpmteN(p), 1); rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p)); rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p)); rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p)); if (tscolor) { rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(p)); rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(p)); } if ((h = rpmdbNextIterator(mi)) != NULL) { rpmteAddProblem(p, RPMPROB_PKG_INSTALLED, NULL, NULL, headerGetInstance(h)); } rpmdbFreeIterator(mi); } if (!(probFilter & RPMPROB_FILTER_FORCERELOCATE)) rpmteAddRelocProblems(p); } rpmtsiFree(pi); return rpmtsProblems(ts); }
static JSBool rpmts_order(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; JSBool ok = JS_FALSE; _METHOD_DEBUG_ENTRY(_debug); if (rpmtsNElements(ts) > 0) (void) rpmcliInstallOrder(ts); /* XXX print ps for now */ ok = JS_TRUE; *rval = BOOLEAN_TO_JSVAL(ok); /* XXX return error */ return ok; }
rpmal rpmtsCreateAl(rpmts ts, rpmElementTypes types) { rpmal al = NULL; if (ts) { rpmte p; rpmtsi pi; rpmstrPool tspool = rpmtsPool(ts); al = rpmalCreate(tspool, (rpmtsNElements(ts) / 4) + 1, rpmtsFlags(ts), rpmtsColor(ts), rpmtsPrefColor(ts)); pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, types))) rpmalAdd(al, p); rpmtsiFree(pi); } return al; }
int rpmtsRebuildDB(rpmts ts) { int rc = -1; rpmtxn txn = NULL; /* Cannot do this on a populated transaction set */ if (rpmtsNElements(ts) > 0) return -1; txn = rpmtxnBegin(ts, RPMTXN_WRITE); if (txn) { if (!(ts->vsflags & RPMVSF_NOHDRCHK)) rc = rpmdbRebuild(ts->rootDir, ts, headerCheck); else rc = rpmdbRebuild(ts->rootDir, NULL, NULL); rpmtxnEnd(txn); } return rc; }
int rpmtsRebuildDB(rpmts ts) { int rc = -1; rpmlock lock = NULL; /* Cannot do this on a populated transaction set */ if (rpmtsNElements(ts) > 0) return -1; lock = rpmtsAcquireLock(ts); if (lock) { if (!(ts->vsflags & RPMVSF_NOHDRCHK)) rc = rpmdbRebuild(ts->rootDir, ts, headerCheck); else rc = rpmdbRebuild(ts->rootDir, NULL, NULL); rpmlockFree(lock); } return rc; }
static JSBool rpmts_run(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; JSBool ok = JS_FALSE; _METHOD_DEBUG_ENTRY(_debug); #ifdef NOTYET /* XXX force --test instead. */ if (rpmtsNElements(ts) > 0) (void) rpmcliInstallRun(ts, NULL, 0); #else rpmtsEmpty(ts); #endif ok = JS_TRUE; *rval = BOOLEAN_TO_JSVAL(ok); /* XXX return error */ return ok; }
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; }
int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) { int rc = -1; /* assume failure */ tsMembers tsmem = rpmtsMembers(ts); rpmtxn txn = NULL; rpmps tsprobs = NULL; int TsmPreDone = 0; /* TsmPre hook hasn't been called */ /* Force default 022 umask during transaction for consistent results */ mode_t oldmask = umask(022); /* Empty transaction, nothing to do */ if (rpmtsNElements(ts) <= 0) { rc = 0; goto exit; } /* If we are in test mode, then there's no need for transaction lock. */ if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { if (!(txn = rpmtxnBegin(ts, RPMTXN_WRITE))) { goto exit; } } /* Setup flags and such, open the DB */ if (rpmtsSetup(ts, ignoreSet)) { goto exit; } /* Check package set for problems */ tsprobs = checkProblems(ts); /* Run pre transaction hook for all plugins */ TsmPreDone = 1; if (rpmpluginsCallTsmPre(rpmtsPlugins(ts), ts) == RPMRC_FAIL) { goto exit; } if (!rpmpsNumProblems(tsprobs)) { /* Run file triggers in this package other package(s) set off. */ runFileTriggers(ts, NULL, RPMSENSE_TRIGGERUN, RPMSCRIPT_TRANSFILETRIGGER, 0); /* Run file triggers in other package(s) this package sets off. */ runTransScripts(ts, PKG_TRANSFILETRIGGERUN); } /* Run pre-transaction scripts, but only if there are no known * problems up to this point and not disabled otherwise. */ if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS)) || (rpmpsNumProblems(tsprobs)))) { rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n"); runTransScripts(ts, PKG_PRETRANS); } tsprobs = rpmpsFree(tsprobs); /* Compute file disposition for each package in transaction set. */ if (rpmtsPrepare(ts)) { goto exit; } /* Check again for problems (now including file conflicts, duh */ tsprobs = rpmtsProblems(ts); /* If unfiltered problems exist, free memory and return. */ if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(tsprobs))) { rc = tsmem->orderCount; goto exit; } /* Free up memory taken by problem sets */ tsprobs = rpmpsFree(tsprobs); rpmtsCleanProblems(ts); /* * Free up the global string pool unless we expect it to be needed * again. During the transaction, private pools will be used for * rpmfi's etc. */ if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))) tsmem->pool = rpmstrPoolFree(tsmem->pool); /* Actually install and remove packages, get final exit code */ rc = rpmtsProcess(ts) ? -1 : 0; /* Run post-transaction scripts unless disabled */ if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS))) { rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n"); runTransScripts(ts, PKG_POSTTRANS); } /* Run file triggers in other package(s) this package sets off. */ runFileTriggers(ts, NULL, RPMSENSE_TRIGGERIN, RPMSCRIPT_TRANSFILETRIGGER, 0); runPostUnTransFileTrigs(ts); /* Run file triggers in this package other package(s) set off. */ runTransScripts(ts, PKG_TRANSFILETRIGGERIN); exit: /* Run post transaction hook for all plugins */ if (TsmPreDone) /* If TsmPre hook has been called, call the TsmPost hook */ rpmpluginsCallTsmPost(rpmtsPlugins(ts), ts, rc); /* Finish up... */ (void) umask(oldmask); (void) rpmtsFinish(ts); rpmpsFree(tsprobs); rpmtxnEnd(txn); return rc; }
int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) { rpm_color_t tscolor = rpmtsColor(ts); int i; int rc = 0; int totalFileCount = 0; rpmfi fi; fingerPrintCache fpc; rpmps ps; rpmtsi pi; rpmte p; int numAdded; int numRemoved; void * lock = NULL; int xx; /* XXX programmer error segfault avoidance. */ if (rpmtsNElements(ts) <= 0) return -1; /* If we are in test mode, then there's no need for transaction lock. */ if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { lock = rpmtsAcquireLock(ts); if (lock == NULL) return -1; /* XXX W2DO? */ } if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS) (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers)); if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS) (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers)); if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers)); /* if SELinux isn't enabled or init fails, don't bother... */ if (!rpmtsSELinuxEnabled(ts)) { rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_NOCONTEXTS)); } if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONTEXTS)) { char *fn = rpmGetPath("%{?_install_file_context_path}", NULL); if (matchpathcon_init(fn) == -1) { rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_NOCONTEXTS)); } free(fn); } ts->probs = rpmpsFree(ts->probs); ts->probs = rpmpsCreate(); /* XXX Make sure the database is open RDWR for package install/erase. */ { int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) ? O_RDONLY : (O_RDWR|O_CREAT); /* Open database RDWR for installing packages. */ if (rpmtsOpenDB(ts, dbmode)) { rpmtsFreeLock(lock); return -1; /* XXX W2DO? */ } } ts->ignoreSet = ignoreSet; { char * currDir = rpmGetCwd(); rpmtsSetCurrDir(ts, currDir); currDir = _free(currDir); } (void) rpmtsSetChrootDone(ts, 0); { rpm_tid_t tid = (rpm_tid_t) time(NULL); (void) rpmtsSetTid(ts, tid); } /* Get available space on mounted file systems. */ xx = rpmtsInitDSI(ts); /* =============================================== * For packages being installed: * - verify package arch/os. * - verify package epoch:version-release is newer. * - count files. * For packages being removed: * - count files. */ rpmlog(RPMLOG_DEBUG, "sanity checking %d elements\n", rpmtsNElements(ts)); ps = rpmtsProblems(ts); /* The ordering doesn't matter here */ pi = rpmtsiInit(ts); /* XXX Only added packages need be checked. */ while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) { rpmdbMatchIterator mi; int fc; if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH)) if (!archOkay(rpmteA(p))) rpmpsAppend(ps, RPMPROB_BADARCH, rpmteNEVRA(p), rpmteKey(p), rpmteA(p), NULL, NULL, 0); if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREOS)) if (!osOkay(rpmteO(p))) rpmpsAppend(ps, RPMPROB_BADOS, rpmteNEVRA(p), rpmteKey(p), rpmteO(p), NULL, NULL, 0); if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_OLDPACKAGE)) { Header h; mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0); while ((h = rpmdbNextIterator(mi)) != NULL) xx = ensureOlder(ts, p, h); mi = rpmdbFreeIterator(mi); } if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG)) { mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0); xx = rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p)); xx = rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p)); xx = rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p)); if (tscolor) { xx = rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(p)); xx = rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(p)); } while (rpmdbNextIterator(mi) != NULL) { rpmpsAppend(ps, RPMPROB_PKG_INSTALLED, rpmteNEVRA(p), rpmteKey(p), NULL, NULL, NULL, 0); break; } mi = rpmdbFreeIterator(mi); } /* Count no. of files (if any). */ totalFileCount += fc; } pi = rpmtsiFree(pi); ps = rpmpsFree(ps); /* The ordering doesn't matter here */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, TR_REMOVED)) != NULL) { int fc; if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); totalFileCount += fc; } pi = rpmtsiFree(pi); /* Run pre-transaction scripts, but only if there are no known * problems up to this point and not disabled otherwise. */ if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_NOPRE)) || (rpmpsNumProblems(ts->probs) && (okProbs == NULL || rpmpsTrim(ts->probs, okProbs))))) { rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n"); runTransScripts(ts, RPMTAG_PRETRANS); } /* =============================================== * Initialize transaction element file info for package: */ /* * FIXME?: we'd be better off assembling one very large file list and * calling fpLookupList only once. I'm not sure that the speedup is * worth the trouble though. */ rpmlog(RPMLOG_DEBUG, "computing %d file fingerprints\n", totalFileCount); numAdded = numRemoved = 0; pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { int fc; if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); switch (rpmteType(p)) { case TR_ADDED: numAdded++; /* Skip netshared paths, not our i18n files, and excluded docs */ if (fc > 0) skipFiles(ts, p); break; case TR_REMOVED: numRemoved++; break; } } pi = rpmtsiFree(pi); if (!rpmtsChrootDone(ts)) { const char * rootDir = rpmtsRootDir(ts); xx = chdir("/"); if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/') { /* opening db before chroot not optimal, see rhbz#103852 c#3 */ xx = rpmdbOpenAll(ts->rdb); if (chroot(rootDir) == -1) { rpmlog(RPMLOG_ERR, _("Unable to change root directory: %m\n")); return -1; } } (void) rpmtsSetChrootDone(ts, 1); } ts->ht = rpmFpHashCreate(totalFileCount/2+1, fpHashFunction, fpEqual, NULL, NULL); rpmFpHash symlinks = rpmFpHashCreate(totalFileCount/16+16, fpHashFunction, fpEqual, NULL, NULL); fpc = fpCacheCreate(totalFileCount/2 + 10001); /* =============================================== * Add fingerprint for each file not skipped. */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { int fc; (void) rpmdbCheckSignals(); if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); rpmfiFpLookup(fi, fpc); /* collect symbolic links */ fi = rpmfiInit(fi, 0); if (fi != NULL) /* XXX lclint */ while ((i = rpmfiNext(fi)) >= 0) { struct rpmffi_s ffi; char const *linktarget; linktarget = rpmfiFLink(fi); if (!(linktarget && *linktarget != '\0')) continue; if (XFA_SKIPPING(rpmfsGetAction(rpmteGetFileStates(p), i))) continue; ffi.p = p; ffi.fileno = i; rpmFpHashAddEntry(symlinks, rpmfiFpsIndex(fi, i), ffi); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc); } pi = rpmtsiFree(pi); /* =============================================== * Check fingerprints if they contain symlinks * and add them to the ts->ht hash table */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { (void) rpmdbCheckSignals(); if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fi = rpmfiInit(fi, 0); (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); if (fi != NULL) /* XXX lclint */ while ((i = rpmfiNext(fi)) >= 0) { if (XFA_SKIPPING(rpmfsGetAction(rpmteGetFileStates(p), i))) continue; fpLookupSubdir(symlinks, ts->ht, fpc, p, i); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); } pi = rpmtsiFree(pi); rpmFpHashFree(symlinks); /* =============================================== * Compute file disposition for each package in transaction set. */ rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_START, 6, ts->orderCount); /* check against files in the rpmdb */ checkInstalledFiles(ts, fpc); pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); /* check files in ts against each other and update disk space needs on each partition for this package. */ handleOverlappedFiles(ts, p, fi); /* Check added package has sufficient space on each partition used. */ if (rpmteType(p) == TR_ADDED) { rpmtsCheckDSIProblems(ts, p); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); } pi = rpmtsiFree(pi); if (rpmtsChrootDone(ts)) { const char * rootDir = rpmtsRootDir(ts); const char * currDir = rpmtsCurrDir(ts); if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/') xx = chroot("."); (void) rpmtsSetChrootDone(ts, 0); if (currDir != NULL) xx = chdir(currDir); } rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_STOP, 6, ts->orderCount); /* =============================================== * Free unused memory as soon as possible. */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { rpmteSetFI(p, NULL); } pi = rpmtsiFree(pi); fpc = fpCacheFree(fpc); ts->ht = rpmFpHashFree(ts->ht); /* =============================================== * If unfiltered problems exist, free memory and return. */ if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(ts->probs) && (okProbs == NULL || rpmpsTrim(ts->probs, okProbs))) ) { rpmtsFreeLock(lock); return ts->orderCount; } /* Actually install and remove packages */ rc = rpmtsProcess(ts); if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_NOPOST))) { rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n"); runTransScripts(ts, RPMTAG_POSTTRANS); } if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONTEXTS)) { matchpathcon_fini(); } rpmtsFreeLock(lock); /* FIX: ts->flList may be NULL */ if (rc) return -1; else return 0; }
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; }
int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) { int rc = -1; /* assume failure */ rpmlock lock = NULL; rpmps tsprobs = NULL; /* Force default 022 umask during transaction for consistent results */ mode_t oldmask = umask(022); /* Empty transaction, nothing to do */ if (rpmtsNElements(ts) <= 0) { rc = 0; goto exit; } /* If we are in test mode, then there's no need for transaction lock. */ if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { if (!(lock = rpmtsAcquireLock(ts))) { goto exit; } } /* Setup flags and such, open the DB */ if (rpmtsSetup(ts, ignoreSet)) { goto exit; } rpmtsSetupCollections(ts); /* Check package set for problems */ tsprobs = checkProblems(ts); /* Run pre-transaction scripts, but only if there are no known * problems up to this point and not disabled otherwise. */ if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRE)) || (rpmpsNumProblems(tsprobs)))) { rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n"); runTransScripts(ts, PKG_PRETRANS); } tsprobs = rpmpsFree(tsprobs); /* Compute file disposition for each package in transaction set. */ if (rpmtsPrepare(ts)) { goto exit; } /* Check again for problems (now including file conflicts, duh */ tsprobs = rpmtsProblems(ts); /* If unfiltered problems exist, free memory and return. */ if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(tsprobs))) { tsMembers tsmem = rpmtsMembers(ts); rc = tsmem->orderCount; goto exit; } /* Free up memory taken by problem sets */ tsprobs = rpmpsFree(tsprobs); rpmtsCleanProblems(ts); /* Actually install and remove packages, get final exit code */ rc = rpmtsProcess(ts) ? -1 : 0; /* Run post-transaction scripts unless disabled */ if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOST))) { rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n"); runTransScripts(ts, PKG_POSTTRANS); } exit: /* Finish up... */ (void) umask(oldmask); (void) rpmtsFinish(ts); rpmpsFree(tsprobs); rpmlockFree(lock); return rc; }