static PyObject * rpmts_Clean(rpmtsObject * s) { rpmtsClean(s->ts); Py_RETURN_NONE; }
uint32_t TDNFRunTransaction( PTDNFRPMTS pTS, PTDNF pTdnf ) { uint32_t dwError = 0; dwError = rpmtsOrder(pTS->pTS); BAIL_ON_TDNF_ERROR(dwError); dwError = doCheck(pTS); BAIL_ON_TDNF_ERROR(dwError); rpmtsClean(pTS->pTS); fprintf(stdout, "Testing transaction\n"); rpmtsSetFlags(pTS->pTS, RPMTRANS_FLAG_TEST); dwError = rpmtsRun(pTS->pTS, NULL, pTS->nProbFilterFlags); BAIL_ON_TDNF_ERROR(dwError); fprintf(stdout, "Running transaction\n"); rpmtsSetFlags(pTS->pTS, RPMTRANS_FLAG_NONE); dwError = rpmtsRun(pTS->pTS, NULL, pTS->nProbFilterFlags); BAIL_ON_TDNF_ERROR(dwError); cleanup: return dwError; error: doCheck(pTS); goto cleanup; }
static int rpmcliTransaction(rpmts ts, struct rpmInstallArguments_s * ia, int numPackages) { rpmps ps; int rc = 0; int stop = 0; int eflags = ia->installInterfaceFlags & INSTALL_ERASE; if (!(ia->installInterfaceFlags & INSTALL_NODEPS)) { if (rpmtsCheck(ts)) { rc = numPackages; stop = 1; } ps = rpmtsProblems(ts); if (!stop && rpmpsNumProblems(ps) > 0) { rpmlog(RPMLOG_ERR, _("Failed dependencies:\n")); rpmpsPrint(NULL, ps); rc = numPackages; stop = 1; } ps = rpmpsFree(ps); } if (!stop && !(ia->installInterfaceFlags & INSTALL_NOORDER)) { if (rpmtsOrder(ts)) { rc = numPackages; stop = 1; } } if (numPackages && !stop) { rpmlog(RPMLOG_DEBUG, eflags ? "erasing packages\n" : "installing binary packages\n"); rpmtsClean(ts); rc = rpmtsRun(ts, NULL, ia->probFilter); ps = rpmtsProblems(ts); if (rpmpsNumProblems(ps) > 0 && (eflags || rc > 0)) rpmpsPrint(NULL, ps); ps = rpmpsFree(ps); } return rc; }
void rpmtsEmpty(rpmts ts) { tsMembers tsmem = rpmtsMembers(ts); if (ts == NULL) return; rpmtsClean(ts); for (int oc = 0; oc < tsmem->orderCount; oc++) { tsmem->order[oc] = rpmteFree(tsmem->order[oc]); } tsmem->orderCount = 0; /* The pool cannot be emptied, there might be references to its contents */ tsmem->pool = rpmstrPoolFree(tsmem->pool); removedHashEmpty(tsmem->removedPackages); return; }
static int checkSpec(rpmts ts, Header h) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies ts, h, rpmGlobalMacroContext, fileSystem, internalState @*/ { int rc; if (!headerIsEntry(h, RPMTAG_REQUIRENAME) && !headerIsEntry(h, RPMTAG_CONFLICTNAME)) return 0; rc = rpmtsAddInstallElement(ts, h, NULL, 0, NULL); rc = rpmcliInstallProblems(ts, _("Failed build dependencies"), rpmtsCheck(ts)); /* XXX nuke the added package. */ rpmtsClean(ts); return rc; }
int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) { char * const * arg; char *qfmt = NULL; int numFailed = 0; int stopUninstall = 0; int numPackages = 0; rpmVSFlags vsflags, ovsflags; rpmps ps; if (argv == NULL) return 0; vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); if (ia->qva_flags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (ia->qva_flags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (ia->qva_flags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; ovsflags = rpmtsSetVSFlags(ts, vsflags); /* XXX suggest mechanism only meaningful when installing */ ia->transFlags |= RPMTRANS_FLAG_NOSUGGEST; (void) rpmtsSetFlags(ts, ia->transFlags); #ifdef NOTYET /* XXX no callbacks on erase yet */ { int notifyFlags, xx; notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); xx = rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags)); } #endif qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL); for (arg = argv; *arg; arg++) { rpmdbMatchIterator mi; int matches = 0; int erasing = 1; /* Iterator count isn't reliable with labels, count manually... */ mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); while (rpmdbNextIterator(mi) != NULL) { matches++; } rpmdbFreeIterator(mi); if (! matches) { rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg); numFailed++; } else { Header h; /* XXX iterator owns the reference */ if (matches > 1 && !(ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES)) { rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n"), *arg); numFailed++; erasing = 0; } mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); while ((h = rpmdbNextIterator(mi)) != NULL) { if (erasing) { (void) rpmtsAddEraseElement(ts, h, -1); numPackages++; } else { char *nevra = headerFormat(h, qfmt, NULL); rpmlog(RPMLOG_NOTICE, " %s", nevra); free(nevra); } } mi = rpmdbFreeIterator(mi); } } free(qfmt); if (numFailed) goto exit; if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) { if (rpmtsCheck(ts)) { numFailed = numPackages; stopUninstall = 1; } ps = rpmtsProblems(ts); if (!stopUninstall && rpmpsNumProblems(ps) > 0) { rpmlog(RPMLOG_ERR, _("Failed dependencies:\n")); rpmpsPrint(NULL, ps); numFailed += numPackages; stopUninstall = 1; } ps = rpmpsFree(ps); } if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) { if (rpmtsOrder(ts)) { numFailed += numPackages; stopUninstall = 1; } } if (numPackages && !stopUninstall) { (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE)); /* Drop added/available package indices and dependency sets. */ rpmtsClean(ts); numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)); ps = rpmtsProblems(ts); if (rpmpsNumProblems(ps) > 0) rpmpsPrint(NULL, ps); numFailed += numPackages; stopUninstall = 1; ps = rpmpsFree(ps); } exit: rpmtsEmpty(ts); return numFailed; }
/** @todo Generalize --freshen policies. */ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv) { struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu)); rpmps ps; rpmprobFilterFlags probFilter; rpmRelocation * relocations; char * fileURL = NULL; int stopInstall = 0; rpmVSFlags vsflags, ovsflags, tvsflags; int rc; int xx; int i; if (fileArgv == NULL) goto exit; rpmcliPackagesTotal = 0; (void) rpmtsSetFlags(ts, ia->transFlags); probFilter = ia->probFilter; relocations = ia->relocations; if (ia->installInterfaceFlags & INSTALL_UPGRADE) vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); else vsflags = rpmExpandNumeric("%{?_vsflags_install}"); if (ia->qva_flags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (ia->qva_flags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (ia->qva_flags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD)); { int notifyFlags; notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); xx = rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags)); } if ((eiu->relocations = relocations) != NULL) { while (eiu->relocations->oldPath) eiu->relocations++; if (eiu->relocations->newPath == NULL) eiu->relocations = NULL; } /* Build fully globbed list of arguments in argv[argc]. */ for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) { ARGV_t av = NULL; int ac = 0; char * fn; fn = rpmEscapeSpaces(*eiu->fnp); rc = rpmGlob(fn, &ac, &av); fn = _free(fn); if (rc || ac == 0) { rpmlog(RPMLOG_ERR, _("File not found by glob: %s\n"), *eiu->fnp); eiu->numFailed++; continue; } argvAppend(&(eiu->argv), av); argvFree(av); eiu->argc += ac; } restart: /* Allocate sufficient storage for next set of args. */ if (eiu->pkgx >= eiu->numPkgs) { eiu->numPkgs = eiu->pkgx + eiu->argc; eiu->pkgURL = xrealloc(eiu->pkgURL, (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL)); memset(eiu->pkgURL + eiu->pkgx, 0, ((eiu->argc + 1) * sizeof(*eiu->pkgURL))); eiu->pkgState = xrealloc(eiu->pkgState, (eiu->numPkgs + 1) * sizeof(*eiu->pkgState)); memset(eiu->pkgState + eiu->pkgx, 0, ((eiu->argc + 1) * sizeof(*eiu->pkgState))); } /* Retrieve next set of args, cache on local storage. */ for (i = 0; i < eiu->argc; i++) { fileURL = _free(fileURL); fileURL = eiu->argv[i]; eiu->argv[i] = NULL; switch (urlIsURL(fileURL)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: { char *tfn; FD_t tfd; if (rpmIsVerbose()) fprintf(stdout, _("Retrieving %s\n"), fileURL); tfd = rpmMkTempFile(rpmtsRootDir(ts), &tfn); if (tfd && tfn) { Fclose(tfd); rc = urlGetFile(fileURL, tfn); } else { rc = -1; } if (rc != 0) { rpmlog(RPMLOG_ERR, _("skipping %s - transfer failed\n"), fileURL); eiu->numFailed++; eiu->pkgURL[eiu->pkgx] = NULL; tfn = _free(tfn); break; } eiu->pkgState[eiu->pkgx] = 1; eiu->pkgURL[eiu->pkgx] = tfn; eiu->pkgx++; } break; case URL_IS_PATH: case URL_IS_DASH: /* WRONG WRONG WRONG */ case URL_IS_HKP: /* WRONG WRONG WRONG */ default: eiu->pkgURL[eiu->pkgx] = fileURL; fileURL = NULL; eiu->pkgx++; break; } } fileURL = _free(fileURL); if (eiu->numFailed) goto exit; /* Continue processing file arguments, building transaction set. */ for (eiu->fnp = eiu->pkgURL+eiu->prevx; *eiu->fnp != NULL; eiu->fnp++, eiu->prevx++) { const char * fileName; rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp); (void) urlPath(*eiu->fnp, &fileName); /* Try to read the header from a package file. */ eiu->fd = Fopen(*eiu->fnp, "r.ufdio"); if (eiu->fd == NULL || Ferror(eiu->fd)) { rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp, Fstrerror(eiu->fd)); if (eiu->fd != NULL) { xx = Fclose(eiu->fd); eiu->fd = NULL; } eiu->numFailed++; *eiu->fnp = NULL; continue; } /* Read the header, verifying signatures (if present). */ tvsflags = rpmtsSetVSFlags(ts, vsflags); eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h); tvsflags = rpmtsSetVSFlags(ts, tvsflags); xx = Fclose(eiu->fd); eiu->fd = NULL; switch (eiu->rpmrc) { case RPMRC_FAIL: rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp); eiu->numFailed++; *eiu->fnp = NULL; continue; break; case RPMRC_NOTFOUND: goto maybe_manifest; break; case RPMRC_NOTTRUSTED: case RPMRC_NOKEY: case RPMRC_OK: default: break; } eiu->isSource = headerIsSource(eiu->h); if (eiu->isSource) { rpmlog(RPMLOG_DEBUG, "\tadded source package [%d]\n", eiu->numSRPMS); eiu->sourceURL = xrealloc(eiu->sourceURL, (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL)); eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp; *eiu->fnp = NULL; eiu->numSRPMS++; eiu->sourceURL[eiu->numSRPMS] = NULL; continue; } if (eiu->relocations) { struct rpmtd_s prefixes; headerGet(eiu->h, RPMTAG_PREFIXES, &prefixes, HEADERGET_DEFAULT); if (rpmtdCount(&prefixes) == 1) { eiu->relocations->oldPath = xstrdup(rpmtdGetString(&prefixes)); rpmtdFreeData(&prefixes); } else { const char * name; xx = headerNVR(eiu->h, &name, NULL, NULL); rpmlog(RPMLOG_ERR, _("package %s is not relocatable\n"), name); eiu->numFailed++; goto exit; } } /* On --freshen, verify package is installed and newer */ if (ia->installInterfaceFlags & INSTALL_FRESHEN) { rpmdbMatchIterator mi; const char * name; Header oldH; int count; xx = headerNVR(eiu->h, &name, NULL, NULL); mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0); count = rpmdbGetIteratorCount(mi); while ((oldH = rpmdbNextIterator(mi)) != NULL) { if (rpmVersionCompare(oldH, eiu->h) < 0) continue; /* same or newer package already installed */ count = 0; break; } mi = rpmdbFreeIterator(mi); if (count == 0) { eiu->h = headerFree(eiu->h); continue; } /* Package is newer than those currently installed. */ } rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName, (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0, relocations); /* XXX reference held by transaction set */ eiu->h = headerFree(eiu->h); if (eiu->relocations) eiu->relocations->oldPath = _free(eiu->relocations->oldPath); switch(rc) { case 0: rpmlog(RPMLOG_DEBUG, "\tadded binary package [%d]\n", eiu->numRPMS); break; case 1: rpmlog(RPMLOG_ERR, _("error reading from file %s\n"), *eiu->fnp); eiu->numFailed++; goto exit; break; case 2: rpmlog(RPMLOG_ERR, _("file %s requires a newer version of RPM\n"), *eiu->fnp); eiu->numFailed++; goto exit; break; default: eiu->numFailed++; goto exit; break; } eiu->numRPMS++; continue; maybe_manifest: /* Try to read a package manifest. */ eiu->fd = Fopen(*eiu->fnp, "r.fpio"); if (eiu->fd == NULL || Ferror(eiu->fd)) { rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp, Fstrerror(eiu->fd)); if (eiu->fd != NULL) { xx = Fclose(eiu->fd); eiu->fd = NULL; } eiu->numFailed++; *eiu->fnp = NULL; break; } /* Read list of packages from manifest. */ /* FIX: *eiu->argv can be NULL */ rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv); if (rc != RPMRC_OK) rpmlog(RPMLOG_ERR, _("%s: not an rpm package (or package manifest): %s\n"), *eiu->fnp, Fstrerror(eiu->fd)); xx = Fclose(eiu->fd); eiu->fd = NULL; /* If successful, restart the query loop. */ if (rc == RPMRC_OK) { eiu->prevx++; goto restart; } eiu->numFailed++; *eiu->fnp = NULL; break; } rpmlog(RPMLOG_DEBUG, "found %d source and %d binary packages\n", eiu->numSRPMS, eiu->numRPMS); if (eiu->numFailed) goto exit; if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) { if (rpmtsCheck(ts)) { eiu->numFailed = eiu->numPkgs; stopInstall = 1; } ps = rpmtsProblems(ts); if (!stopInstall && rpmpsNumProblems(ps) > 0) { rpmlog(RPMLOG_ERR, _("Failed dependencies:\n")); rpmpsPrint(NULL, ps); eiu->numFailed = eiu->numPkgs; stopInstall = 1; } ps = rpmpsFree(ps); } if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) { if (rpmtsOrder(ts)) { eiu->numFailed = eiu->numPkgs; stopInstall = 1; } } if (eiu->numRPMS && !stopInstall) { rpmcliPackagesTotal += eiu->numSRPMS; rpmlog(RPMLOG_DEBUG, "installing binary packages\n"); /* Drop added/available package indices and dependency sets. */ rpmtsClean(ts); rc = rpmtsRun(ts, NULL, probFilter); ps = rpmtsProblems(ts); if (rc < 0) { eiu->numFailed += eiu->numRPMS; } else if (rc > 0) { eiu->numFailed += rc; if (rpmpsNumProblems(ps) > 0) rpmpsPrint(stderr, ps); } ps = rpmpsFree(ps); } if (eiu->numSRPMS && !stopInstall) { if (eiu->sourceURL != NULL) for (i = 0; i < eiu->numSRPMS; i++) { rpmdbCheckSignals(); if (eiu->sourceURL[i] == NULL) continue; eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio"); if (eiu->fd == NULL || Ferror(eiu->fd)) { rpmlog(RPMLOG_ERR, _("cannot open file %s: %s\n"), eiu->sourceURL[i], Fstrerror(eiu->fd)); if (eiu->fd != NULL) { xx = Fclose(eiu->fd); eiu->fd = NULL; } continue; } if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL); if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++; } xx = Fclose(eiu->fd); eiu->fd = NULL; } } exit: if (eiu->pkgURL != NULL) for (i = 0; i < eiu->numPkgs; i++) { if (eiu->pkgURL[i] == NULL) continue; if (eiu->pkgState[i] == 1) (void) unlink(eiu->pkgURL[i]); eiu->pkgURL[i] = _free(eiu->pkgURL[i]); } eiu->pkgState = _free(eiu->pkgState); eiu->pkgURL = _free(eiu->pkgURL); eiu->argv = _free(eiu->argv); rc = eiu->numFailed; free(eiu); rpmtsEmpty(ts); return rc; }
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; }
int ssds_rpm_process(GSList *install, GSList *update, GSList *erase) { /*********************************************************/ /* Installing / Updating / Erasing packages */ /*********************************************************/ // required variables for rpmlib int rc = OK; rpmts ts; rpmReadConfigFiles(NULL, NULL); ts = rpmtsCreate(); rpmtsSetRootDir(ts, NULL); if(install != NULL) { ssds_log(logMESSAGE, "Installing packages.\n"); for(GSList *elem = install; elem; elem = g_slist_next(elem)) { LrPackageTarget *target = (LrPackageTarget *)elem->data; if(!target->err) { ssds_add_to_transaction(ts, target->local_path, SSDS_INSTALL); }else{ ssds_log(logERROR, "Package Error: %s\n", target->err); rc = INSTALL_ERROR; goto rpmEnd; } } } if(update != NULL) { ssds_log(logMESSAGE, "Updating packages.\n"); for(GSList *elem = update; elem; elem = g_slist_next(elem)) { LrPackageTarget *target = (LrPackageTarget *)elem->data; if(!target->err) { ssds_add_to_transaction(ts, target->local_path, SSDS_UPDATE); }else{ ssds_log(logERROR, "Package Error: %s\n", target->err); rc = UPDATE_ERROR; goto rpmEnd; } } } if(g_slist_length(erase) > 1) { ssds_log(logMESSAGE, "Erasing packages.\n"); for(guint i = 1; i < g_slist_length(erase); i++) { SsdsJsonPkg *pkg = (SsdsJsonPkg*)g_slist_nth_data(erase,i); rc = ssds_add_to_erase(ts, pkg->pkg_name); if(rc != OK){ ssds_log(logERROR, "Unable to erase requested package.\n"); rc = ERASE_ERROR; goto rpmEnd; } } } rpmprobFilterFlags flag = 0; int nf = 0; nf |= INSTALL_LABEL | INSTALL_HASH; rpmtsSetNotifyCallback(ts, rpmShowProgress,(void *) nf); rc = rpmtsRun(ts, NULL, flag); rpmEnd: rpmtsClean(ts); rpmtsFree(ts); return rc; }
int main(int argc, char **argv) { rpmts ts; rpmps probs; int probFilter = 0; int notifyFlags = 0; int tsFlags = 0; int rc = 0; /* Read configuration, initialize transaction */ rpmReadConfigFiles(NULL, NULL); ts = rpmtsCreate(); /* Set verification flags if needed, for example --nomd5 */ /* rpmtsSetVSFlags(ts, rpmtsVSFlags(ts) | RPMVSF_NOMD5); */ /* Open rpmdb */ //rpmtsSetRootDir(ts, NULL); rc = rpmtsOpenDB(ts, O_RDWR); if (rc) { printf("Error opening rpmdb\n"); goto exit; } /* Add packages for install/upgrade/erase */ while (optind < argc) { int upgrade = 0; switch (getopt(argc, argv, "i:U:e:")) { case 'U': upgrade = 1; case 'i': add_for_install(ts, optarg, upgrade); break; case 'e': add_for_erase(ts, optarg); break; default: printf("usage ...\n"); goto exit; } } /* Set problem filters if needed, for example --oldpackage */ /* rpmbFilter |= RPMPROB_FILTER_OLDPACKAGE /* /* Set transaction flags if needed, for example --excludedocs */ /* tsFlags |= RPMTRANS_FLAG_NODOCS */ /* Check transaction sanity */ rc = rpmtsCheck(ts); probs = rpmtsProblems(ts); if (rc || rpmpsNumProblems(probs)) { rpmpsPrint(NULL, probs); rpmpsFree(probs); goto exit; } /* Create ordering for the transaction */ rc = rpmtsOrder(ts); if (rc > 0) { printf("Ordering failed\n"); goto exit; } rpmtsClean(ts); /* Set callback routine & flags, for example -vh */ notifyFlags |= INSTALL_LABEL | INSTALL_HASH; rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *)notifyFlags); /* Set transaction flags and run the actual transaction */ rpmtsSetFlags(ts, (rpmtransFlags)(rpmtsFlags(ts) | tsFlags)); rc = rpmtsRun(ts, NULL, (rpmprobFilterFlags)probFilter); /* Check for results .. */ if (rc || rpmpsNumProblems(probs) > 0) rpmpsPrint(stderr, probs); rpmpsFree(probs); exit: /* ..and clean up */ rpmtsFree(ts); exit(rc); }