2 * \file lib/rpminstall.c
12 #include "rpmte.h" /* XXX: rpmts.h needs this for rpmtsScoreEntries */
13 #define _RPMTS_INTERNAL /* ts->goal, ts->dbmode, ts->suggests */
20 int rpmcliPackagesTotal = 0;
21 int rpmcliHashesCurrent = 0;
22 int rpmcliHashesTotal = 0;
23 int rpmcliProgressCurrent = 0;
24 int rpmcliProgressTotal = 0;
27 * Print a CLI progress bar.
28 * @todo Unsnarl isatty(STDOUT_FILENO) from the control flow.
29 * @param amount current
32 static void printHash(const unsigned long amount, const unsigned long total)
36 rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50);
38 if (rpmcliHashesCurrent != rpmcliHashesTotal) {
39 float pct = (total ? (((float) amount) / total) : 1.0);
40 hashesNeeded = (rpmcliHashesTotal * pct) + 0.5;
41 while (hashesNeeded > rpmcliHashesCurrent) {
42 if (isatty (STDOUT_FILENO)) {
44 for (i = 0; i < rpmcliHashesCurrent; i++)
46 for (; i < rpmcliHashesTotal; i++)
48 fprintf(stdout, "(%3d%%)", (int)((100 * pct) + 0.5));
49 for (i = 0; i < (rpmcliHashesTotal + 6); i++)
50 (void) putchar ('\b');
54 rpmcliHashesCurrent++;
56 (void) fflush(stdout);
58 if (rpmcliHashesCurrent == rpmcliHashesTotal) {
60 rpmcliProgressCurrent++;
61 if (isatty(STDOUT_FILENO)) {
62 for (i = 1; i < rpmcliHashesCurrent; i++)
64 pct = (rpmcliProgressTotal
65 ? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal)
67 fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5));
69 fprintf(stdout, "\n");
71 (void) fflush(stdout);
75 void * rpmShowProgress(const void * arg,
76 const rpmCallbackType what,
77 const unsigned long amount,
78 const unsigned long total,
82 Header h = (Header) arg;
84 int flags = (int) ((long)data);
86 const char * filename = (const char *)key;
87 static FD_t fd = NULL;
91 case RPMCALLBACK_INST_OPEN_FILE:
92 if (filename == NULL || filename[0] == '\0')
94 fd = Fopen(filename, "r.ufdio");
95 /* FIX: still necessary? */
96 if (fd == NULL || Ferror(fd)) {
97 rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), filename,
104 fd = fdLink(fd, "persist (showProgress)");
108 case RPMCALLBACK_INST_CLOSE_FILE:
109 /* FIX: still necessary? */
110 fd = fdFree(fd, "persist (showProgress)");
117 case RPMCALLBACK_INST_START:
118 rpmcliHashesCurrent = 0;
119 if (h == NULL || !(flags & INSTALL_LABEL))
121 /* @todo Remove headerSprintf() on a progress callback. */
122 if (flags & INSTALL_HASH) {
123 s = headerSprintf(h, "%{NAME}",
124 rpmTagTable, rpmHeaderFormats, NULL);
125 if (isatty (STDOUT_FILENO))
126 fprintf(stdout, "%4d:%-23.23s", rpmcliProgressCurrent + 1, s);
128 fprintf(stdout, "%-28.28s", s);
129 (void) fflush(stdout);
132 s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
133 rpmTagTable, rpmHeaderFormats, NULL);
134 fprintf(stdout, "%s\n", s);
135 (void) fflush(stdout);
140 case RPMCALLBACK_TRANS_PROGRESS:
141 case RPMCALLBACK_INST_PROGRESS:
142 if (flags & INSTALL_PERCENT)
143 fprintf(stdout, "%%%% %f\n", (double) (total
144 ? ((((float) amount) / total) * 100)
146 else if (flags & INSTALL_HASH)
147 printHash(amount, total);
148 (void) fflush(stdout);
151 case RPMCALLBACK_TRANS_START:
152 rpmcliHashesCurrent = 0;
153 rpmcliProgressTotal = 1;
154 rpmcliProgressCurrent = 0;
155 if (!(flags & INSTALL_LABEL))
157 if (flags & INSTALL_HASH)
158 fprintf(stdout, "%-28s", _("Preparing..."));
160 fprintf(stdout, "%s\n", _("Preparing packages for installation..."));
161 (void) fflush(stdout);
164 case RPMCALLBACK_TRANS_STOP:
165 if (flags & INSTALL_HASH)
166 printHash(1, 1); /* Fixes "preparing..." progress bar */
167 rpmcliProgressTotal = rpmcliPackagesTotal;
168 rpmcliProgressCurrent = 0;
171 case RPMCALLBACK_REPACKAGE_START:
172 rpmcliHashesCurrent = 0;
173 rpmcliProgressTotal = total;
174 rpmcliProgressCurrent = 0;
175 if (!(flags & INSTALL_LABEL))
177 if (flags & INSTALL_HASH)
178 fprintf(stdout, "%-28s\n", _("Repackaging..."));
180 fprintf(stdout, "%s\n", _("Repackaging erased files..."));
181 (void) fflush(stdout);
184 case RPMCALLBACK_REPACKAGE_PROGRESS:
185 if (amount && (flags & INSTALL_HASH))
186 printHash(1, 1); /* Fixes "preparing..." progress bar */
189 case RPMCALLBACK_REPACKAGE_STOP:
190 rpmcliProgressTotal = total;
191 rpmcliProgressCurrent = total;
192 if (flags & INSTALL_HASH)
193 printHash(1, 1); /* Fixes "preparing..." progress bar */
194 rpmcliProgressTotal = rpmcliPackagesTotal;
195 rpmcliProgressCurrent = 0;
196 if (!(flags & INSTALL_LABEL))
198 if (flags & INSTALL_HASH)
199 fprintf(stdout, "%-28s\n", _("Upgrading..."));
201 fprintf(stdout, "%s\n", _("Upgrading packages..."));
202 (void) fflush(stdout);
205 case RPMCALLBACK_UNINST_PROGRESS:
207 case RPMCALLBACK_UNINST_START:
209 case RPMCALLBACK_UNINST_STOP:
211 case RPMCALLBACK_UNPACK_ERROR:
213 case RPMCALLBACK_CPIO_ERROR:
215 case RPMCALLBACK_UNKNOWN:
223 typedef const char * str_t;
241 rpmRelocation * relocations;
245 /** @todo Generalize --freshen policies. */
246 int rpmInstall(rpmts ts,
247 struct rpmInstallArguments_s * ia,
248 const char ** fileArgv)
250 struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu));
252 rpmprobFilterFlags probFilter;
253 rpmRelocation * relocations;
254 const char * fileURL = NULL;
256 const char ** av = NULL;
257 rpmVSFlags vsflags, ovsflags, tvsflags;
263 if (fileArgv == NULL) goto exit;
265 ts->goal = TSM_INSTALL;
266 rpmcliPackagesTotal = 0;
268 if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
269 ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
271 (void) rpmtsSetFlags(ts, ia->transFlags);
273 probFilter = ia->probFilter;
274 relocations = ia->relocations;
276 if (ia->installInterfaceFlags & INSTALL_UPGRADE)
277 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
279 vsflags = rpmExpandNumeric("%{?_vsflags_install}");
280 if (ia->qva_flags & VERIFY_DIGEST)
281 vsflags |= _RPMVSF_NODIGESTS;
282 if (ia->qva_flags & VERIFY_SIGNATURE)
283 vsflags |= _RPMVSF_NOSIGNATURES;
284 if (ia->qva_flags & VERIFY_HDRCHK)
285 vsflags |= RPMVSF_NOHDRCHK;
286 ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
289 notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
290 xx = rpmtsSetNotifyCallback(ts,
291 rpmShowProgress, (void *) ((long)notifyFlags));
294 if ((eiu->relocations = relocations) != NULL) {
295 while (eiu->relocations->oldPath)
297 if (eiu->relocations->newPath == NULL)
298 eiu->relocations = NULL;
301 /* Build fully globbed list of arguments in argv[argc]. */
302 for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
303 av = _free(av); ac = 0;
304 rc = rpmGlob(*eiu->fnp, &ac, &av);
306 rpmlog(RPMERR_OPEN, _("File not found by glob: %s\n"), *eiu->fnp);
310 eiu->argv = xrealloc(eiu->argv, (eiu->argc+ac+1) * sizeof(*eiu->argv));
311 memcpy(eiu->argv+eiu->argc, av, ac * sizeof(*av));
313 eiu->argv[eiu->argc] = NULL;
315 av = _free(av); ac = 0;
318 /* Allocate sufficient storage for next set of args. */
319 if (eiu->pkgx >= eiu->numPkgs) {
320 eiu->numPkgs = eiu->pkgx + eiu->argc;
321 eiu->pkgURL = xrealloc(eiu->pkgURL,
322 (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL));
323 memset(eiu->pkgURL + eiu->pkgx, 0,
324 ((eiu->argc + 1) * sizeof(*eiu->pkgURL)));
325 eiu->pkgState = xrealloc(eiu->pkgState,
326 (eiu->numPkgs + 1) * sizeof(*eiu->pkgState));
327 memset(eiu->pkgState + eiu->pkgx, 0,
328 ((eiu->argc + 1) * sizeof(*eiu->pkgState)));
331 /* Retrieve next set of args, cache on local storage. */
332 for (i = 0; i < eiu->argc; i++) {
333 fileURL = _free(fileURL);
334 fileURL = eiu->argv[i];
338 if (fileURL[0] == '=') {
339 rpmds this = rpmdsSingle(RPMTAG_REQUIRENAME, fileURL+1, NULL, 0);
341 xx = rpmtsSolve(ts, this, NULL);
342 if (ts->suggests && ts->nsuggests > 0) {
343 fileURL = _free(fileURL);
344 fileURL = ts->suggests[0];
345 ts->suggests[0] = NULL;
346 while (ts->nsuggests-- > 0) {
347 if (ts->suggests[ts->nsuggests] == NULL)
349 ts->suggests[ts->nsuggests] = _free(ts->suggests[ts->nsuggests]);
351 ts->suggests = _free(ts->suggests);
352 rpmlog(RPMLOG_DEBUG, _("Adding goal: %s\n"), fileURL);
353 eiu->pkgURL[eiu->pkgx] = fileURL;
357 this = rpmdsFree(this);
361 switch (urlIsURL(fileURL)) {
368 fprintf(stdout, _("Retrieving %s\n"), fileURL);
371 const char * rootDir = rpmtsRootDir(ts);
372 if (!(rootDir && * rootDir))
374 strcpy(tfnbuf, "rpm-xfer.XXXXXX");
375 (void) mktemp(tfnbuf);
376 tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
379 /* XXX undefined %{name}/%{version}/%{release} here */
380 /* XXX %{_tmpdir} does not exist */
381 rpmlog(RPMLOG_DEBUG, _(" ... as %s\n"), tfn);
382 rc = urlGetFile(fileURL, tfn);
385 _("skipping %s - transfer failed - %s\n"),
386 fileURL, ftpStrerror(rc));
388 eiu->pkgURL[eiu->pkgx] = NULL;
392 eiu->pkgState[eiu->pkgx] = 1;
393 eiu->pkgURL[eiu->pkgx] = tfn;
397 case URL_IS_DASH: /* WRONG WRONG WRONG */
398 case URL_IS_HKP: /* WRONG WRONG WRONG */
400 eiu->pkgURL[eiu->pkgx] = fileURL;
406 fileURL = _free(fileURL);
408 if (eiu->numFailed) goto exit;
410 /* Continue processing file arguments, building transaction set. */
411 for (eiu->fnp = eiu->pkgURL+eiu->prevx;
413 eiu->fnp++, eiu->prevx++)
415 const char * fileName;
417 rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp);
418 (void) urlPath(*eiu->fnp, &fileName);
420 /* Try to read the header from a package file. */
421 eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
422 if (eiu->fd == NULL || Ferror(eiu->fd)) {
423 rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
425 if (eiu->fd != NULL) {
426 xx = Fclose(eiu->fd);
429 eiu->numFailed++; *eiu->fnp = NULL;
433 /* Read the header, verifying signatures (if present). */
434 tvsflags = rpmtsSetVSFlags(ts, vsflags);
435 eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
436 tvsflags = rpmtsSetVSFlags(ts, tvsflags);
437 xx = Fclose(eiu->fd);
440 switch (eiu->rpmrc) {
442 rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
443 eiu->numFailed++; *eiu->fnp = NULL;
449 case RPMRC_NOTTRUSTED:
456 eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
459 rpmlog(RPMLOG_DEBUG, _("\tadded source package [%d]\n"),
461 eiu->sourceURL = xrealloc(eiu->sourceURL,
462 (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
463 eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
466 eiu->sourceURL[eiu->numSRPMS] = NULL;
470 if (eiu->relocations) {
475 if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
476 (void **) &paths, &c) && (c == 1))
478 eiu->relocations->oldPath = xstrdup(paths[0]);
479 paths = headerFreeData(paths, pft);
482 xx = headerNVR(eiu->h, &name, NULL, NULL);
484 _("package %s is not relocatable\n"), name);
490 /* On --freshen, verify package is installed and newer */
491 if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
492 rpmdbMatchIterator mi;
497 xx = headerNVR(eiu->h, &name, NULL, NULL);
498 mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
499 count = rpmdbGetIteratorCount(mi);
500 while ((oldH = rpmdbNextIterator(mi)) != NULL) {
501 if (rpmVersionCompare(oldH, eiu->h) < 0)
503 /* same or newer package already installed */
507 mi = rpmdbFreeIterator(mi);
509 eiu->h = headerFree(eiu->h);
512 /* Package is newer than those currently installed. */
515 rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
516 (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
519 /* XXX reference held by transaction set */
520 eiu->h = headerFree(eiu->h);
521 if (eiu->relocations)
522 eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
526 rpmlog(RPMLOG_DEBUG, _("\tadded binary package [%d]\n"),
531 _("error reading from file %s\n"), *eiu->fnp);
537 _("file %s requires a newer version of RPM\n"),
552 /* Try to read a package manifest. */
553 eiu->fd = Fopen(*eiu->fnp, "r.fpio");
554 if (eiu->fd == NULL || Ferror(eiu->fd)) {
555 rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
557 if (eiu->fd != NULL) {
558 xx = Fclose(eiu->fd);
561 eiu->numFailed++; *eiu->fnp = NULL;
565 /* Read list of packages from manifest. */
566 /* FIX: *eiu->argv can be NULL */
567 rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
569 rpmlog(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
570 *eiu->fnp, Fstrerror(eiu->fd));
571 xx = Fclose(eiu->fd);
574 /* If successful, restart the query loop. */
575 if (rc == RPMRC_OK) {
580 eiu->numFailed++; *eiu->fnp = NULL;
584 rpmlog(RPMLOG_DEBUG, _("found %d source and %d binary packages\n"),
585 eiu->numSRPMS, eiu->numRPMS);
587 if (eiu->numFailed) goto exit;
589 if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
591 if (rpmtsCheck(ts)) {
592 eiu->numFailed = eiu->numPkgs;
596 ps = rpmtsProblems(ts);
597 if (!stopInstall && rpmpsNumProblems(ps) > 0) {
598 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
599 rpmpsPrint(NULL, ps);
600 eiu->numFailed = eiu->numPkgs;
603 if (ts->suggests != NULL && ts->nsuggests > 0) {
604 rpmlog(RPMLOG_NOTICE, _(" Suggested resolutions:\n"));
605 for (i = 0; i < ts->nsuggests; i++) {
606 const char * str = ts->suggests[i];
611 rpmlog(RPMLOG_NOTICE, "\t%s\n", str);
613 ts->suggests[i] = NULL;
616 ts->suggests = _free(ts->suggests);
622 if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
623 if (rpmtsOrder(ts)) {
624 eiu->numFailed = eiu->numPkgs;
629 if (eiu->numRPMS && !stopInstall) {
631 rpmcliPackagesTotal += eiu->numSRPMS;
633 rpmlog(RPMLOG_DEBUG, _("installing binary packages\n"));
635 /* Drop added/available package indices and dependency sets. */
638 rc = rpmtsRun(ts, NULL, probFilter);
639 ps = rpmtsProblems(ts);
642 eiu->numFailed += eiu->numRPMS;
644 eiu->numFailed += rc;
645 if (rpmpsNumProblems(ps) > 0)
646 rpmpsPrint(stderr, ps);
651 if (eiu->numSRPMS && !stopInstall) {
652 if (eiu->sourceURL != NULL)
653 for (i = 0; i < eiu->numSRPMS; i++) {
655 if (eiu->sourceURL[i] == NULL) continue;
656 eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
657 if (eiu->fd == NULL || Ferror(eiu->fd)) {
658 rpmlog(RPMLOG_ERR, _("cannot open file %s: %s\n"),
659 eiu->sourceURL[i], Fstrerror(eiu->fd));
660 if (eiu->fd != NULL) {
661 xx = Fclose(eiu->fd);
667 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
668 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
669 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
672 xx = Fclose(eiu->fd);
678 if (eiu->pkgURL != NULL)
679 for (i = 0; i < eiu->numPkgs; i++) {
680 if (eiu->pkgURL[i] == NULL) continue;
681 if (eiu->pkgState[i] == 1)
682 (void) Unlink(eiu->pkgURL[i]);
683 eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
685 eiu->pkgState = _free(eiu->pkgState);
686 eiu->pkgURL = _free(eiu->pkgURL);
687 eiu->argv = _free(eiu->argv);
691 return eiu->numFailed;
694 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
700 int stopUninstall = 0;
702 rpmVSFlags vsflags, ovsflags;
705 if (argv == NULL) return 0;
707 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
708 if (ia->qva_flags & VERIFY_DIGEST)
709 vsflags |= _RPMVSF_NODIGESTS;
710 if (ia->qva_flags & VERIFY_SIGNATURE)
711 vsflags |= _RPMVSF_NOSIGNATURES;
712 if (ia->qva_flags & VERIFY_HDRCHK)
713 vsflags |= RPMVSF_NOHDRCHK;
714 ovsflags = rpmtsSetVSFlags(ts, vsflags);
716 if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
717 ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
719 (void) rpmtsSetFlags(ts, ia->transFlags);
721 #ifdef NOTYET /* XXX no callbacks on erase yet */
723 notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
724 xx = rpmtsSetNotifyCallback(ts,
725 rpmShowProgress, (void *) ((long)notifyFlags)
729 ts->goal = TSM_ERASE;
731 for (arg = argv; *arg; arg++) {
732 rpmdbMatchIterator mi;
734 /* XXX HACK to get rpmdbFindByLabel out of the API */
735 mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
737 rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg);
740 Header h; /* XXX iterator owns the reference */
742 while ((h = rpmdbNextIterator(mi)) != NULL) {
743 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
745 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
746 rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages\n"),
752 (void) rpmtsAddEraseElement(ts, h, recOffset);
757 mi = rpmdbFreeIterator(mi);
760 if (numFailed) goto exit;
762 if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
764 if (rpmtsCheck(ts)) {
765 numFailed = numPackages;
769 ps = rpmtsProblems(ts);
770 if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
771 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
772 rpmpsPrint(NULL, ps);
773 numFailed += numPackages;
779 if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
780 if (rpmtsOrder(ts)) {
781 numFailed += numPackages;
786 if (numPackages && !stopUninstall) {
787 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
789 /* Drop added/available package indices and dependency sets. */
792 numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
793 ps = rpmtsProblems(ts);
794 if (rpmpsNumProblems(ps) > 0)
795 rpmpsPrint(NULL, ps);
796 numFailed += numPackages;
807 int rpmInstallSource(rpmts ts, const char * arg,
808 const char ** specFilePtr, const char ** cookie)
814 fd = Fopen(arg, "r.ufdio");
815 if (fd == NULL || Ferror(fd)) {
816 rpmlog(RPMLOG_ERR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
817 if (fd != NULL) (void) Fclose(fd);
822 fprintf(stdout, _("Installing %s\n"), arg);
825 rpmVSFlags ovsflags =
826 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
827 rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
828 rc = (rpmrc == RPMRC_OK ? 0 : 1);
829 ovsflags = rpmtsSetVSFlags(ts, ovsflags);
832 rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), arg);
833 if (specFilePtr && *specFilePtr)
834 *specFilePtr = _free(*specFilePtr);
835 if (cookie && *cookie)
836 *cookie = _free(*cookie);
844 /** @todo Transaction handling, more, needs work. */
845 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
847 int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
848 unsigned thistid = 0xffffffff;
858 int vsflags, ovsflags;
862 int _unsafe_rollbacks = 0;
863 rpmtransFlags transFlags = ia->transFlags;
865 if (argv != NULL && *argv != NULL) {
870 _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
872 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
873 if (ia->qva_flags & VERIFY_DIGEST)
874 vsflags |= _RPMVSF_NODIGESTS;
875 if (ia->qva_flags & VERIFY_SIGNATURE)
876 vsflags |= _RPMVSF_NOSIGNATURES;
877 if (ia->qva_flags & VERIFY_HDRCHK)
878 vsflags |= RPMVSF_NOHDRCHK;
879 vsflags |= RPMVSF_NEEDPAYLOAD; /* XXX no legacy signatures */
880 ovsflags = rpmtsSetVSFlags(ts, vsflags);
882 (void) rpmtsSetFlags(ts, transFlags);
884 /* Make the transaction a rollback transaction. In a rollback
885 * a best effort is what we want
887 rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
889 itids = IDTXload(ts, RPMTAG_INSTALLTID);
898 { const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
899 if (globstr == NULL || *globstr == '%') {
900 globstr = _free(globstr);
904 rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
913 globstr = _free(globstr);
916 { int notifyFlags, xx;
917 notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
918 xx = rpmtsSetNotifyCallback(ts,
919 rpmShowProgress, (void *) ((long)notifyFlags));
922 /* Run transactions until rollback goal is achieved. */
926 rpmcliPackagesTotal = 0;
929 ia->installInterfaceFlags &= ~ifmask;
931 /* Find larger of the remaining install/erase transaction id's. */
933 if (ip != NULL && ip->val.u32 > thistid)
934 thistid = ip->val.u32;
935 if (rp != NULL && rp->val.u32 > thistid)
936 thistid = rp->val.u32;
938 /* If we've achieved the rollback goal, then we're done. */
939 if (thistid == 0 || thistid < ia->rbtid)
942 /* If we've reached the (configured) rollback goal, then we're done. */
943 if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
947 (void) rpmtsSetFlags(ts, transFlags);
949 /* Install the previously erased packages for this transaction. */
950 while (rp != NULL && rp->val.u32 == thistid) {
952 rpmlog(RPMLOG_DEBUG, "\t+++ install %s\n",
953 (rp->key ? rp->key : "???"));
955 rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
961 rpmcliPackagesTotal++;
962 if (!(ia->installInterfaceFlags & ifmask))
963 ia->installInterfaceFlags |= INSTALL_UPGRADE;
966 rp->h = headerFree(rp->h);
975 /* Erase the previously installed packages for this transaction. */
976 while (ip != NULL && ip->val.u32 == thistid) {
979 "\t--- erase h#%u\n", ip->instance);
981 rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
987 if (_unsafe_rollbacks)
988 rpmcliPackagesTotal++;
990 if (!(ia->installInterfaceFlags & ifmask)) {
991 ia->installInterfaceFlags |= INSTALL_ERASE;
992 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
1005 /* Anything to do? */
1006 if (rpmcliPackagesTotal <= 0)
1009 tid = (time_t)thistid;
1010 rpmlog(RPMLOG_NOTICE,
1011 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
1012 numAdded, numRemoved, ctime(&tid), tid);
1014 rc = rpmtsCheck(ts);
1015 ps = rpmtsProblems(ts);
1016 if (rc != 0 && rpmpsNumProblems(ps) > 0) {
1017 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
1018 rpmpsPrint(NULL, ps);
1024 rc = rpmtsOrder(ts);
1028 /* Drop added/available package indices and dependency sets. */
1031 rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
1032 ps = rpmtsProblems(ts);
1033 if (rc > 0 && rpmpsNumProblems(ps) > 0)
1034 rpmpsPrint(stderr, ps);
1039 /* Clean up after successful rollback. */
1040 if (rtids && !rpmIsDebug()) {
1042 rpmlog(RPMLOG_NOTICE, _("Cleaning up repackaged packages:\n"));
1044 for (i = 0; i < rtids->nidt; i++) {
1045 IDT rrp = rtids->idt + i;
1046 if (rrp->val.u32 != thistid)
1048 if (rrp->key) { /* XXX can't happen */
1049 rpmlog(RPMLOG_NOTICE, _("\tRemoving %s:\n"), rrp->key);
1050 (void) unlink(rrp->key); /* XXX: Should check rc??? */
1059 rtids = IDTXfree(rtids);
1060 itids = IDTXfree(itids);
1063 (void) rpmtsSetFlags(ts, transFlags);