2 * \file lib/rpminstall.c
12 #define _RPMTS_INTERNAL /* ts->goal, ts->suggests */
19 int rpmcliPackagesTotal = 0;
20 int rpmcliHashesCurrent = 0;
21 int rpmcliHashesTotal = 0;
22 int rpmcliProgressCurrent = 0;
23 int rpmcliProgressTotal = 0;
26 * Print a CLI progress bar.
27 * @todo Unsnarl isatty(STDOUT_FILENO) from the control flow.
28 * @param amount current
31 static void printHash(const unsigned long amount, const unsigned long total)
35 rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50);
37 if (rpmcliHashesCurrent != rpmcliHashesTotal) {
38 float pct = (total ? (((float) amount) / total) : 1.0);
39 hashesNeeded = (rpmcliHashesTotal * pct) + 0.5;
40 while (hashesNeeded > rpmcliHashesCurrent) {
41 if (isatty (STDOUT_FILENO)) {
43 for (i = 0; i < rpmcliHashesCurrent; i++)
45 for (; i < rpmcliHashesTotal; i++)
47 fprintf(stdout, "(%3d%%)", (int)((100 * pct) + 0.5));
48 for (i = 0; i < (rpmcliHashesTotal + 6); i++)
49 (void) putchar ('\b');
53 rpmcliHashesCurrent++;
55 (void) fflush(stdout);
57 if (rpmcliHashesCurrent == rpmcliHashesTotal) {
59 rpmcliProgressCurrent++;
60 if (isatty(STDOUT_FILENO)) {
61 for (i = 1; i < rpmcliHashesCurrent; i++)
63 pct = (rpmcliProgressTotal
64 ? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal)
66 fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5));
68 fprintf(stdout, "\n");
70 (void) fflush(stdout);
74 void * rpmShowProgress(const void * arg,
75 const rpmCallbackType what,
76 const unsigned long amount,
77 const unsigned long total,
81 Header h = (Header) arg;
83 int flags = (int) ((long)data);
85 const char * filename = (const char *)key;
86 static FD_t fd = NULL;
90 case RPMCALLBACK_INST_OPEN_FILE:
91 if (filename == NULL || filename[0] == '\0')
93 fd = Fopen(filename, "r.ufdio");
94 /* FIX: still necessary? */
95 if (fd == NULL || Ferror(fd)) {
96 rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), filename,
103 fd = fdLink(fd, "persist (showProgress)");
107 case RPMCALLBACK_INST_CLOSE_FILE:
108 /* FIX: still necessary? */
109 fd = fdFree(fd, "persist (showProgress)");
116 case RPMCALLBACK_INST_START:
117 rpmcliHashesCurrent = 0;
118 if (h == NULL || !(flags & INSTALL_LABEL))
120 /* @todo Remove headerSprintf() on a progress callback. */
121 if (flags & INSTALL_HASH) {
122 s = headerSprintf(h, "%{NAME}",
123 rpmTagTable, rpmHeaderFormats, NULL);
124 if (isatty (STDOUT_FILENO))
125 fprintf(stdout, "%4d:%-23.23s", rpmcliProgressCurrent + 1, s);
127 fprintf(stdout, "%-28.28s", s);
128 (void) fflush(stdout);
131 s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
132 rpmTagTable, rpmHeaderFormats, NULL);
133 fprintf(stdout, "%s\n", s);
134 (void) fflush(stdout);
139 case RPMCALLBACK_TRANS_PROGRESS:
140 case RPMCALLBACK_INST_PROGRESS:
141 if (flags & INSTALL_PERCENT)
142 fprintf(stdout, "%%%% %f\n", (double) (total
143 ? ((((float) amount) / total) * 100)
145 else if (flags & INSTALL_HASH)
146 printHash(amount, total);
147 (void) fflush(stdout);
150 case RPMCALLBACK_TRANS_START:
151 rpmcliHashesCurrent = 0;
152 rpmcliProgressTotal = 1;
153 rpmcliProgressCurrent = 0;
154 if (!(flags & INSTALL_LABEL))
156 if (flags & INSTALL_HASH)
157 fprintf(stdout, "%-28s", _("Preparing..."));
159 fprintf(stdout, "%s\n", _("Preparing packages for installation..."));
160 (void) fflush(stdout);
163 case RPMCALLBACK_TRANS_STOP:
164 if (flags & INSTALL_HASH)
165 printHash(1, 1); /* Fixes "preparing..." progress bar */
166 rpmcliProgressTotal = rpmcliPackagesTotal;
167 rpmcliProgressCurrent = 0;
170 case RPMCALLBACK_REPACKAGE_START:
171 rpmcliHashesCurrent = 0;
172 rpmcliProgressTotal = total;
173 rpmcliProgressCurrent = 0;
174 if (!(flags & INSTALL_LABEL))
176 if (flags & INSTALL_HASH)
177 fprintf(stdout, "%-28s\n", _("Repackaging..."));
179 fprintf(stdout, "%s\n", _("Repackaging erased files..."));
180 (void) fflush(stdout);
183 case RPMCALLBACK_REPACKAGE_PROGRESS:
184 if (amount && (flags & INSTALL_HASH))
185 printHash(1, 1); /* Fixes "preparing..." progress bar */
188 case RPMCALLBACK_REPACKAGE_STOP:
189 rpmcliProgressTotal = total;
190 rpmcliProgressCurrent = total;
191 if (flags & INSTALL_HASH)
192 printHash(1, 1); /* Fixes "preparing..." progress bar */
193 rpmcliProgressTotal = rpmcliPackagesTotal;
194 rpmcliProgressCurrent = 0;
195 if (!(flags & INSTALL_LABEL))
197 if (flags & INSTALL_HASH)
198 fprintf(stdout, "%-28s\n", _("Upgrading..."));
200 fprintf(stdout, "%s\n", _("Upgrading packages..."));
201 (void) fflush(stdout);
204 case RPMCALLBACK_UNINST_PROGRESS:
206 case RPMCALLBACK_UNINST_START:
208 case RPMCALLBACK_UNINST_STOP:
210 case RPMCALLBACK_UNPACK_ERROR:
212 case RPMCALLBACK_CPIO_ERROR:
214 case RPMCALLBACK_UNKNOWN:
222 typedef const char * str_t;
240 rpmRelocation * relocations;
244 /** @todo Generalize --freshen policies. */
245 int rpmInstall(rpmts ts,
246 struct rpmInstallArguments_s * ia,
247 const char ** fileArgv)
249 struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu));
251 rpmprobFilterFlags probFilter;
252 rpmRelocation * relocations;
253 const char * fileURL = NULL;
255 const char ** av = NULL;
256 rpmVSFlags vsflags, ovsflags, tvsflags;
262 if (fileArgv == NULL) goto exit;
264 ts->goal = TSM_INSTALL;
265 rpmcliPackagesTotal = 0;
267 if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
268 ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
270 (void) rpmtsSetFlags(ts, ia->transFlags);
272 probFilter = ia->probFilter;
273 relocations = ia->relocations;
275 if (ia->installInterfaceFlags & INSTALL_UPGRADE)
276 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
278 vsflags = rpmExpandNumeric("%{?_vsflags_install}");
279 if (ia->qva_flags & VERIFY_DIGEST)
280 vsflags |= _RPMVSF_NODIGESTS;
281 if (ia->qva_flags & VERIFY_SIGNATURE)
282 vsflags |= _RPMVSF_NOSIGNATURES;
283 if (ia->qva_flags & VERIFY_HDRCHK)
284 vsflags |= RPMVSF_NOHDRCHK;
285 ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
288 notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
289 xx = rpmtsSetNotifyCallback(ts,
290 rpmShowProgress, (void *) ((long)notifyFlags));
293 if ((eiu->relocations = relocations) != NULL) {
294 while (eiu->relocations->oldPath)
296 if (eiu->relocations->newPath == NULL)
297 eiu->relocations = NULL;
300 /* Build fully globbed list of arguments in argv[argc]. */
301 for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
302 av = _free(av); ac = 0;
303 rc = rpmGlob(*eiu->fnp, &ac, &av);
305 rpmlog(RPMERR_OPEN, _("File not found by glob: %s\n"), *eiu->fnp);
309 eiu->argv = xrealloc(eiu->argv, (eiu->argc+ac+1) * sizeof(*eiu->argv));
310 memcpy(eiu->argv+eiu->argc, av, ac * sizeof(*av));
312 eiu->argv[eiu->argc] = NULL;
314 av = _free(av); ac = 0;
317 /* Allocate sufficient storage for next set of args. */
318 if (eiu->pkgx >= eiu->numPkgs) {
319 eiu->numPkgs = eiu->pkgx + eiu->argc;
320 eiu->pkgURL = xrealloc(eiu->pkgURL,
321 (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL));
322 memset(eiu->pkgURL + eiu->pkgx, 0,
323 ((eiu->argc + 1) * sizeof(*eiu->pkgURL)));
324 eiu->pkgState = xrealloc(eiu->pkgState,
325 (eiu->numPkgs + 1) * sizeof(*eiu->pkgState));
326 memset(eiu->pkgState + eiu->pkgx, 0,
327 ((eiu->argc + 1) * sizeof(*eiu->pkgState)));
330 /* Retrieve next set of args, cache on local storage. */
331 for (i = 0; i < eiu->argc; i++) {
332 fileURL = _free(fileURL);
333 fileURL = eiu->argv[i];
337 if (fileURL[0] == '=') {
338 rpmds this = rpmdsSingle(RPMTAG_REQUIRENAME, fileURL+1, NULL, 0);
340 xx = rpmtsSolve(ts, this, NULL);
341 if (ts->suggests && ts->nsuggests > 0) {
342 fileURL = _free(fileURL);
343 fileURL = ts->suggests[0];
344 ts->suggests[0] = NULL;
345 while (ts->nsuggests-- > 0) {
346 if (ts->suggests[ts->nsuggests] == NULL)
348 ts->suggests[ts->nsuggests] = _free(ts->suggests[ts->nsuggests]);
350 ts->suggests = _free(ts->suggests);
351 rpmlog(RPMLOG_DEBUG, _("Adding goal: %s\n"), fileURL);
352 eiu->pkgURL[eiu->pkgx] = fileURL;
356 this = rpmdsFree(this);
360 switch (urlIsURL(fileURL)) {
367 fprintf(stdout, _("Retrieving %s\n"), fileURL);
370 const char * rootDir = rpmtsRootDir(ts);
371 if (!(rootDir && * rootDir))
373 strcpy(tfnbuf, "rpm-xfer.XXXXXX");
374 (void) mktemp(tfnbuf);
375 tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
378 /* XXX undefined %{name}/%{version}/%{release} here */
379 /* XXX %{_tmpdir} does not exist */
380 rpmlog(RPMLOG_DEBUG, _(" ... as %s\n"), tfn);
381 rc = urlGetFile(fileURL, tfn);
384 _("skipping %s - transfer failed - %s\n"),
385 fileURL, ftpStrerror(rc));
387 eiu->pkgURL[eiu->pkgx] = NULL;
391 eiu->pkgState[eiu->pkgx] = 1;
392 eiu->pkgURL[eiu->pkgx] = tfn;
396 case URL_IS_DASH: /* WRONG WRONG WRONG */
397 case URL_IS_HKP: /* WRONG WRONG WRONG */
399 eiu->pkgURL[eiu->pkgx] = fileURL;
405 fileURL = _free(fileURL);
407 if (eiu->numFailed) goto exit;
409 /* Continue processing file arguments, building transaction set. */
410 for (eiu->fnp = eiu->pkgURL+eiu->prevx;
412 eiu->fnp++, eiu->prevx++)
414 const char * fileName;
416 rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp);
417 (void) urlPath(*eiu->fnp, &fileName);
419 /* Try to read the header from a package file. */
420 eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
421 if (eiu->fd == NULL || Ferror(eiu->fd)) {
422 rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
424 if (eiu->fd != NULL) {
425 xx = Fclose(eiu->fd);
428 eiu->numFailed++; *eiu->fnp = NULL;
432 /* Read the header, verifying signatures (if present). */
433 tvsflags = rpmtsSetVSFlags(ts, vsflags);
434 eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
435 tvsflags = rpmtsSetVSFlags(ts, tvsflags);
436 xx = Fclose(eiu->fd);
439 switch (eiu->rpmrc) {
441 rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
442 eiu->numFailed++; *eiu->fnp = NULL;
448 case RPMRC_NOTTRUSTED:
455 eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
458 rpmlog(RPMLOG_DEBUG, _("\tadded source package [%d]\n"),
460 eiu->sourceURL = xrealloc(eiu->sourceURL,
461 (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
462 eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
465 eiu->sourceURL[eiu->numSRPMS] = NULL;
469 if (eiu->relocations) {
474 if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
475 (void **) &paths, &c) && (c == 1))
477 eiu->relocations->oldPath = xstrdup(paths[0]);
478 paths = headerFreeData(paths, pft);
481 xx = headerNVR(eiu->h, &name, NULL, NULL);
483 _("package %s is not relocatable\n"), name);
489 /* On --freshen, verify package is installed and newer */
490 if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
491 rpmdbMatchIterator mi;
496 xx = headerNVR(eiu->h, &name, NULL, NULL);
497 mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
498 count = rpmdbGetIteratorCount(mi);
499 while ((oldH = rpmdbNextIterator(mi)) != NULL) {
500 if (rpmVersionCompare(oldH, eiu->h) < 0)
502 /* same or newer package already installed */
506 mi = rpmdbFreeIterator(mi);
508 eiu->h = headerFree(eiu->h);
511 /* Package is newer than those currently installed. */
514 rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
515 (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
518 /* XXX reference held by transaction set */
519 eiu->h = headerFree(eiu->h);
520 if (eiu->relocations)
521 eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
525 rpmlog(RPMLOG_DEBUG, _("\tadded binary package [%d]\n"),
530 _("error reading from file %s\n"), *eiu->fnp);
536 _("file %s requires a newer version of RPM\n"),
551 /* Try to read a package manifest. */
552 eiu->fd = Fopen(*eiu->fnp, "r.fpio");
553 if (eiu->fd == NULL || Ferror(eiu->fd)) {
554 rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
556 if (eiu->fd != NULL) {
557 xx = Fclose(eiu->fd);
560 eiu->numFailed++; *eiu->fnp = NULL;
564 /* Read list of packages from manifest. */
565 /* FIX: *eiu->argv can be NULL */
566 rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
568 rpmlog(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
569 *eiu->fnp, Fstrerror(eiu->fd));
570 xx = Fclose(eiu->fd);
573 /* If successful, restart the query loop. */
574 if (rc == RPMRC_OK) {
579 eiu->numFailed++; *eiu->fnp = NULL;
583 rpmlog(RPMLOG_DEBUG, _("found %d source and %d binary packages\n"),
584 eiu->numSRPMS, eiu->numRPMS);
586 if (eiu->numFailed) goto exit;
588 if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
590 if (rpmtsCheck(ts)) {
591 eiu->numFailed = eiu->numPkgs;
595 ps = rpmtsProblems(ts);
596 if (!stopInstall && rpmpsNumProblems(ps) > 0) {
597 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
598 rpmpsPrint(NULL, ps);
599 eiu->numFailed = eiu->numPkgs;
602 if (ts->suggests != NULL && ts->nsuggests > 0) {
603 rpmlog(RPMLOG_NOTICE, _(" Suggested resolutions:\n"));
604 for (i = 0; i < ts->nsuggests; i++) {
605 const char * str = ts->suggests[i];
610 rpmlog(RPMLOG_NOTICE, "\t%s\n", str);
612 ts->suggests[i] = NULL;
615 ts->suggests = _free(ts->suggests);
621 if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
622 if (rpmtsOrder(ts)) {
623 eiu->numFailed = eiu->numPkgs;
628 if (eiu->numRPMS && !stopInstall) {
630 rpmcliPackagesTotal += eiu->numSRPMS;
632 rpmlog(RPMLOG_DEBUG, _("installing binary packages\n"));
634 /* Drop added/available package indices and dependency sets. */
637 rc = rpmtsRun(ts, NULL, probFilter);
638 ps = rpmtsProblems(ts);
641 eiu->numFailed += eiu->numRPMS;
643 eiu->numFailed += rc;
644 if (rpmpsNumProblems(ps) > 0)
645 rpmpsPrint(stderr, ps);
650 if (eiu->numSRPMS && !stopInstall) {
651 if (eiu->sourceURL != NULL)
652 for (i = 0; i < eiu->numSRPMS; i++) {
654 if (eiu->sourceURL[i] == NULL) continue;
655 eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
656 if (eiu->fd == NULL || Ferror(eiu->fd)) {
657 rpmlog(RPMLOG_ERR, _("cannot open file %s: %s\n"),
658 eiu->sourceURL[i], Fstrerror(eiu->fd));
659 if (eiu->fd != NULL) {
660 xx = Fclose(eiu->fd);
666 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
667 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
668 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
671 xx = Fclose(eiu->fd);
677 if (eiu->pkgURL != NULL)
678 for (i = 0; i < eiu->numPkgs; i++) {
679 if (eiu->pkgURL[i] == NULL) continue;
680 if (eiu->pkgState[i] == 1)
681 (void) Unlink(eiu->pkgURL[i]);
682 eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
684 eiu->pkgState = _free(eiu->pkgState);
685 eiu->pkgURL = _free(eiu->pkgURL);
686 eiu->argv = _free(eiu->argv);
690 return eiu->numFailed;
693 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
699 int stopUninstall = 0;
701 rpmVSFlags vsflags, ovsflags;
704 if (argv == NULL) return 0;
706 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
707 if (ia->qva_flags & VERIFY_DIGEST)
708 vsflags |= _RPMVSF_NODIGESTS;
709 if (ia->qva_flags & VERIFY_SIGNATURE)
710 vsflags |= _RPMVSF_NOSIGNATURES;
711 if (ia->qva_flags & VERIFY_HDRCHK)
712 vsflags |= RPMVSF_NOHDRCHK;
713 ovsflags = rpmtsSetVSFlags(ts, vsflags);
715 if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
716 ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
718 (void) rpmtsSetFlags(ts, ia->transFlags);
720 #ifdef NOTYET /* XXX no callbacks on erase yet */
721 { int notifyFlags, xx;
722 notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
723 xx = rpmtsSetNotifyCallback(ts,
724 rpmShowProgress, (void *) ((long)notifyFlags));
728 ts->goal = TSM_ERASE;
730 for (arg = argv; *arg; arg++) {
731 rpmdbMatchIterator mi;
733 /* XXX HACK to get rpmdbFindByLabel out of the API */
734 mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
736 rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg);
739 Header h; /* XXX iterator owns the reference */
741 while ((h = rpmdbNextIterator(mi)) != NULL) {
742 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
744 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
745 rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages\n"),
751 (void) rpmtsAddEraseElement(ts, h, recOffset);
756 mi = rpmdbFreeIterator(mi);
759 if (numFailed) goto exit;
761 if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
763 if (rpmtsCheck(ts)) {
764 numFailed = numPackages;
768 ps = rpmtsProblems(ts);
769 if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
770 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
771 rpmpsPrint(NULL, ps);
772 numFailed += numPackages;
778 if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
779 if (rpmtsOrder(ts)) {
780 numFailed += numPackages;
785 if (numPackages && !stopUninstall) {
786 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
788 /* Drop added/available package indices and dependency sets. */
791 numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
792 ps = rpmtsProblems(ts);
793 if (rpmpsNumProblems(ps) > 0)
794 rpmpsPrint(NULL, ps);
795 numFailed += numPackages;
806 int rpmInstallSource(rpmts ts, const char * arg,
807 const char ** specFilePtr, const char ** cookie)
813 fd = Fopen(arg, "r.ufdio");
814 if (fd == NULL || Ferror(fd)) {
815 rpmlog(RPMLOG_ERR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
816 if (fd != NULL) (void) Fclose(fd);
821 fprintf(stdout, _("Installing %s\n"), arg);
824 rpmVSFlags ovsflags =
825 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
826 rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
827 rc = (rpmrc == RPMRC_OK ? 0 : 1);
828 ovsflags = rpmtsSetVSFlags(ts, ovsflags);
831 rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), arg);
832 if (specFilePtr && *specFilePtr)
833 *specFilePtr = _free(*specFilePtr);
834 if (cookie && *cookie)
835 *cookie = _free(*cookie);
843 /** @todo Transaction handling, more, needs work. */
844 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
846 int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
847 unsigned thistid = 0xffffffff;
857 int vsflags, ovsflags;
861 int _unsafe_rollbacks = 0;
862 rpmtransFlags transFlags = ia->transFlags;
864 if (argv != NULL && *argv != NULL) {
869 _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
871 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
872 if (ia->qva_flags & VERIFY_DIGEST)
873 vsflags |= _RPMVSF_NODIGESTS;
874 if (ia->qva_flags & VERIFY_SIGNATURE)
875 vsflags |= _RPMVSF_NOSIGNATURES;
876 if (ia->qva_flags & VERIFY_HDRCHK)
877 vsflags |= RPMVSF_NOHDRCHK;
878 vsflags |= RPMVSF_NEEDPAYLOAD; /* XXX no legacy signatures */
879 ovsflags = rpmtsSetVSFlags(ts, vsflags);
881 (void) rpmtsSetFlags(ts, transFlags);
883 /* Make the transaction a rollback transaction. In a rollback
884 * a best effort is what we want
886 rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
888 itids = IDTXload(ts, RPMTAG_INSTALLTID);
897 { const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
898 if (globstr == NULL || *globstr == '%') {
899 globstr = _free(globstr);
903 rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
912 globstr = _free(globstr);
915 { int notifyFlags, xx;
916 notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
917 xx = rpmtsSetNotifyCallback(ts,
918 rpmShowProgress, (void *) ((long)notifyFlags));
921 /* Run transactions until rollback goal is achieved. */
925 rpmcliPackagesTotal = 0;
928 ia->installInterfaceFlags &= ~ifmask;
930 /* Find larger of the remaining install/erase transaction id's. */
932 if (ip != NULL && ip->val.u32 > thistid)
933 thistid = ip->val.u32;
934 if (rp != NULL && rp->val.u32 > thistid)
935 thistid = rp->val.u32;
937 /* If we've achieved the rollback goal, then we're done. */
938 if (thistid == 0 || thistid < ia->rbtid)
941 /* If we've reached the (configured) rollback goal, then we're done. */
942 if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
946 (void) rpmtsSetFlags(ts, transFlags);
948 /* Install the previously erased packages for this transaction. */
949 while (rp != NULL && rp->val.u32 == thistid) {
951 rpmlog(RPMLOG_DEBUG, "\t+++ install %s\n",
952 (rp->key ? rp->key : "???"));
954 rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
960 rpmcliPackagesTotal++;
961 if (!(ia->installInterfaceFlags & ifmask))
962 ia->installInterfaceFlags |= INSTALL_UPGRADE;
965 rp->h = headerFree(rp->h);
974 /* Erase the previously installed packages for this transaction. */
975 while (ip != NULL && ip->val.u32 == thistid) {
978 "\t--- erase h#%u\n", ip->instance);
980 rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
986 if (_unsafe_rollbacks)
987 rpmcliPackagesTotal++;
989 if (!(ia->installInterfaceFlags & ifmask)) {
990 ia->installInterfaceFlags |= INSTALL_ERASE;
991 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
1004 /* Anything to do? */
1005 if (rpmcliPackagesTotal <= 0)
1008 tid = (time_t)thistid;
1009 rpmlog(RPMLOG_NOTICE,
1010 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
1011 numAdded, numRemoved, ctime(&tid), tid);
1013 rc = rpmtsCheck(ts);
1014 ps = rpmtsProblems(ts);
1015 if (rc != 0 && rpmpsNumProblems(ps) > 0) {
1016 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
1017 rpmpsPrint(NULL, ps);
1023 rc = rpmtsOrder(ts);
1027 /* Drop added/available package indices and dependency sets. */
1030 rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
1031 ps = rpmtsProblems(ts);
1032 if (rc > 0 && rpmpsNumProblems(ps) > 0)
1033 rpmpsPrint(stderr, ps);
1038 /* Clean up after successful rollback. */
1039 if (rtids && !rpmIsDebug()) {
1041 rpmlog(RPMLOG_NOTICE, _("Cleaning up repackaged packages:\n"));
1043 for (i = 0; i < rtids->nidt; i++) {
1044 IDT rrp = rtids->idt + i;
1045 if (rrp->val.u32 != thistid)
1047 if (rrp->key) { /* XXX can't happen */
1048 rpmlog(RPMLOG_NOTICE, _("\tRemoving %s:\n"), rrp->key);
1049 (void) unlink(rrp->key); /* XXX: Should check rc??? */
1058 rtids = IDTXfree(rtids);
1059 itids = IDTXfree(itids);
1062 (void) rpmtsSetFlags(ts, transFlags);