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 */
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);
383 rpmlog(RPMMESS_ERROR,
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(RPMMESS_ERROR, _("%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);
482 rpmlog(RPMMESS_ERROR,
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"),
529 rpmlog(RPMMESS_ERROR,
530 _("error reading from file %s\n"), *eiu->fnp);
535 rpmlog(RPMMESS_ERROR,
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(RPMMESS_ERROR, _("Failed dependencies:\n"));
598 rpmpsPrint(NULL, ps);
599 eiu->numFailed = eiu->numPkgs;
602 if (ts->suggests != NULL && ts->nsuggests > 0) {
603 rpmlog(RPMMESS_NORMAL, _(" Suggested resolutions:\n"));
604 for (i = 0; i < ts->nsuggests; i++) {
605 const char * str = ts->suggests[i];
610 rpmlog(RPMMESS_NORMAL, "\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++) {
653 if (eiu->sourceURL[i] == NULL) continue;
654 eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
655 if (eiu->fd == NULL || Ferror(eiu->fd)) {
656 rpmlog(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
657 eiu->sourceURL[i], Fstrerror(eiu->fd));
658 if (eiu->fd != NULL) {
659 xx = Fclose(eiu->fd);
665 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
666 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
667 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
670 xx = Fclose(eiu->fd);
676 if (eiu->pkgURL != NULL)
677 for (i = 0; i < eiu->numPkgs; i++) {
678 if (eiu->pkgURL[i] == NULL) continue;
679 if (eiu->pkgState[i] == 1)
680 (void) Unlink(eiu->pkgURL[i]);
681 eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
683 eiu->pkgState = _free(eiu->pkgState);
684 eiu->pkgURL = _free(eiu->pkgURL);
685 eiu->argv = _free(eiu->argv);
689 return eiu->numFailed;
692 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
698 int stopUninstall = 0;
700 rpmVSFlags vsflags, ovsflags;
703 if (argv == NULL) return 0;
705 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
706 if (ia->qva_flags & VERIFY_DIGEST)
707 vsflags |= _RPMVSF_NODIGESTS;
708 if (ia->qva_flags & VERIFY_SIGNATURE)
709 vsflags |= _RPMVSF_NOSIGNATURES;
710 if (ia->qva_flags & VERIFY_HDRCHK)
711 vsflags |= RPMVSF_NOHDRCHK;
712 ovsflags = rpmtsSetVSFlags(ts, vsflags);
714 if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
715 ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
717 (void) rpmtsSetFlags(ts, ia->transFlags);
719 #ifdef NOTYET /* XXX no callbacks on erase yet */
721 notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
722 xx = rpmtsSetNotifyCallback(ts,
723 rpmShowProgress, (void *) ((long)notifyFlags)
727 ts->goal = TSM_ERASE;
729 for (arg = argv; *arg; arg++) {
730 rpmdbMatchIterator mi;
732 /* XXX HACK to get rpmdbFindByLabel out of the API */
733 mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
735 rpmlog(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
738 Header h; /* XXX iterator owns the reference */
740 while ((h = rpmdbNextIterator(mi)) != NULL) {
741 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
743 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
744 rpmlog(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
750 (void) rpmtsAddEraseElement(ts, h, recOffset);
755 mi = rpmdbFreeIterator(mi);
758 if (numFailed) goto exit;
760 if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
762 if (rpmtsCheck(ts)) {
763 numFailed = numPackages;
767 ps = rpmtsProblems(ts);
768 if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
769 rpmlog(RPMMESS_ERROR, _("Failed dependencies:\n"));
770 rpmpsPrint(NULL, ps);
771 numFailed += numPackages;
777 if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
778 if (rpmtsOrder(ts)) {
779 numFailed += numPackages;
784 if (numPackages && !stopUninstall) {
785 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
787 /* Drop added/available package indices and dependency sets. */
790 numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
791 ps = rpmtsProblems(ts);
792 if (rpmpsNumProblems(ps) > 0)
793 rpmpsPrint(NULL, ps);
794 numFailed += numPackages;
805 int rpmInstallSource(rpmts ts, const char * arg,
806 const char ** specFilePtr, const char ** cookie)
812 fd = Fopen(arg, "r.ufdio");
813 if (fd == NULL || Ferror(fd)) {
814 rpmlog(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
815 if (fd != NULL) (void) Fclose(fd);
820 fprintf(stdout, _("Installing %s\n"), arg);
823 rpmVSFlags ovsflags =
824 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
825 rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
826 rc = (rpmrc == RPMRC_OK ? 0 : 1);
827 ovsflags = rpmtsSetVSFlags(ts, ovsflags);
830 rpmlog(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
831 if (specFilePtr && *specFilePtr)
832 *specFilePtr = _free(*specFilePtr);
833 if (cookie && *cookie)
834 *cookie = _free(*cookie);
842 /** @todo Transaction handling, more, needs work. */
843 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
845 int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
846 unsigned thistid = 0xffffffff;
856 int vsflags, ovsflags;
860 int _unsafe_rollbacks = 0;
861 rpmtransFlags transFlags = ia->transFlags;
863 if (argv != NULL && *argv != NULL) {
868 _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
870 vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
871 if (ia->qva_flags & VERIFY_DIGEST)
872 vsflags |= _RPMVSF_NODIGESTS;
873 if (ia->qva_flags & VERIFY_SIGNATURE)
874 vsflags |= _RPMVSF_NOSIGNATURES;
875 if (ia->qva_flags & VERIFY_HDRCHK)
876 vsflags |= RPMVSF_NOHDRCHK;
877 vsflags |= RPMVSF_NEEDPAYLOAD; /* XXX no legacy signatures */
878 ovsflags = rpmtsSetVSFlags(ts, vsflags);
880 (void) rpmtsSetFlags(ts, transFlags);
882 /* Make the transaction a rollback transaction. In a rollback
883 * a best effort is what we want
885 rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
887 itids = IDTXload(ts, RPMTAG_INSTALLTID);
896 { const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
897 if (globstr == NULL || *globstr == '%') {
898 globstr = _free(globstr);
902 rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
911 globstr = _free(globstr);
914 { int notifyFlags, xx;
915 notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
916 xx = rpmtsSetNotifyCallback(ts,
917 rpmShowProgress, (void *) ((long)notifyFlags));
920 /* Run transactions until rollback goal is achieved. */
924 rpmcliPackagesTotal = 0;
927 ia->installInterfaceFlags &= ~ifmask;
929 /* Find larger of the remaining install/erase transaction id's. */
931 if (ip != NULL && ip->val.u32 > thistid)
932 thistid = ip->val.u32;
933 if (rp != NULL && rp->val.u32 > thistid)
934 thistid = rp->val.u32;
936 /* If we've achieved the rollback goal, then we're done. */
937 if (thistid == 0 || thistid < ia->rbtid)
940 /* If we've reached the (configured) rollback goal, then we're done. */
941 if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
945 (void) rpmtsSetFlags(ts, transFlags);
947 /* Install the previously erased packages for this transaction. */
948 while (rp != NULL && rp->val.u32 == thistid) {
950 rpmlog(RPMLOG_DEBUG, "\t+++ install %s\n",
951 (rp->key ? rp->key : "???"));
953 rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
959 rpmcliPackagesTotal++;
960 if (!(ia->installInterfaceFlags & ifmask))
961 ia->installInterfaceFlags |= INSTALL_UPGRADE;
964 rp->h = headerFree(rp->h);
973 /* Erase the previously installed packages for this transaction. */
974 while (ip != NULL && ip->val.u32 == thistid) {
977 "\t--- erase h#%u\n", ip->instance);
979 rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
985 if (_unsafe_rollbacks)
986 rpmcliPackagesTotal++;
988 if (!(ia->installInterfaceFlags & ifmask)) {
989 ia->installInterfaceFlags |= INSTALL_ERASE;
990 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
1003 /* Anything to do? */
1004 if (rpmcliPackagesTotal <= 0)
1007 tid = (time_t)thistid;
1008 rpmlog(RPMMESS_NORMAL,
1009 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
1010 numAdded, numRemoved, ctime(&tid), tid);
1012 rc = rpmtsCheck(ts);
1013 ps = rpmtsProblems(ts);
1014 if (rc != 0 && rpmpsNumProblems(ps) > 0) {
1015 rpmlog(RPMMESS_ERROR, _("Failed dependencies:\n"));
1016 rpmpsPrint(NULL, ps);
1022 rc = rpmtsOrder(ts);
1026 /* Drop added/available package indices and dependency sets. */
1029 rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
1030 ps = rpmtsProblems(ts);
1031 if (rc > 0 && rpmpsNumProblems(ps) > 0)
1032 rpmpsPrint(stderr, ps);
1037 /* Clean up after successful rollback. */
1038 if (rtids && !rpmIsDebug()) {
1040 rpmlog(RPMMESS_NORMAL, _("Cleaning up repackaged packages:\n"));
1042 for (i = 0; i < rtids->nidt; i++) {
1043 IDT rrp = rtids->idt + i;
1044 if (rrp->val.u32 != thistid)
1046 if (rrp->key) { /* XXX can't happen */
1047 rpmlog(RPMMESS_NORMAL, _("\tRemoving %s:\n"), rrp->key);
1048 (void) unlink(rrp->key); /* XXX: Should check rc??? */
1057 rtids = IDTXfree(rtids);
1058 itids = IDTXfree(itids);
1061 (void) rpmtsSetFlags(ts, transFlags);