00001
00006 #include "system.h"
00007
00008 #include <rpmio_internal.h>
00009 #include <rpmlib.h>
00010 #include <rpmmacro.h>
00011 #include <rpmurl.h>
00012 #include <rpmlua.h>
00013
00014 #include "cpio.h"
00015 #include "fsm.h"
00016 #include "psm.h"
00017
00018 #include "rpmds.h"
00019
00020 #define _RPMFI_INTERNAL
00021 #include "rpmfi.h"
00022
00023 #define _RPMTE_INTERNAL
00024 #include "rpmte.h"
00025
00026 #define _RPMTS_INTERNAL
00027 #include "rpmts.h"
00028
00029 #include "rpmlead.h"
00030 #include "signature.h"
00031 #include "legacy.h"
00032 #include "misc.h"
00033 #include "rpmdb.h"
00034 #include "debug.h"
00035
00036 #define _PSM_DEBUG 0
00037
00038 int _psm_debug = _PSM_DEBUG;
00039
00040 int _psm_threads = 0;
00041
00042
00043
00044
00045
00046
00047 extern unsigned int myinstall_instance;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 int rpmVersionCompare(Header first, Header second)
00062 {
00063 const char * one, * two;
00064 int_32 * epochOne, * epochTwo;
00065 static int_32 zero = 0;
00066 int rc;
00067
00068 if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
00069 epochOne = &zero;
00070 if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo, NULL))
00071 epochTwo = &zero;
00072
00073
00074 if (*epochOne < *epochTwo)
00075 return -1;
00076 else if (*epochOne > *epochTwo)
00077 return 1;
00078
00079
00080 rc = headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
00081 rc = headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
00082
00083 rc = rpmvercmp(one, two);
00084 if (rc)
00085 return rc;
00086
00087 rc = headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
00088 rc = headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
00089
00090 return rpmvercmp(one, two);
00091 }
00092
00097
00098 static struct tagMacro {
00099 const char * macroname;
00100 rpmTag tag;
00101 } tagMacros[] = {
00102 { "name", RPMTAG_NAME },
00103 { "version", RPMTAG_VERSION },
00104 { "release", RPMTAG_RELEASE },
00105 { "epoch", RPMTAG_EPOCH },
00106 { NULL, 0 }
00107 };
00108
00115 static int rpmInstallLoadMacros(rpmfi fi, Header h)
00116
00117
00118 {
00119 HGE_t hge = (HGE_t) fi->hge;
00120 struct tagMacro * tagm;
00121 union {
00122 void * ptr;
00123 const char ** argv;
00124 const char * str;
00125 int_32 * i32p;
00126 } body;
00127 char numbuf[32];
00128 rpmTagType type;
00129
00130 for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
00131 if (!hge(h, tagm->tag, &type, (void **) &body, NULL))
00132 continue;
00133 switch (type) {
00134 case RPM_INT32_TYPE:
00135
00136 sprintf(numbuf, "%d", *body.i32p);
00137
00138 addMacro(NULL, tagm->macroname, NULL, numbuf, -1);
00139 break;
00140 case RPM_STRING_TYPE:
00141 addMacro(NULL, tagm->macroname, NULL, body.str, -1);
00142 break;
00143 case RPM_NULL_TYPE:
00144 case RPM_CHAR_TYPE:
00145 case RPM_INT8_TYPE:
00146 case RPM_INT16_TYPE:
00147 case RPM_BIN_TYPE:
00148 case RPM_STRING_ARRAY_TYPE:
00149 case RPM_I18NSTRING_TYPE:
00150 default:
00151 break;
00152 }
00153 }
00154 return 0;
00155 }
00156
00162
00163 static rpmRC markReplacedFiles(const rpmpsm psm)
00164
00165
00166 {
00167 const rpmts ts = psm->ts;
00168 rpmfi fi = psm->fi;
00169 HGE_t hge = (HGE_t)fi->hge;
00170 sharedFileInfo replaced = fi->replaced;
00171 sharedFileInfo sfi;
00172 rpmdbMatchIterator mi;
00173 Header h;
00174 unsigned int * offsets;
00175 unsigned int prev;
00176 int num, xx;
00177
00178 if (!(rpmfiFC(fi) > 0 && fi->replaced))
00179 return RPMRC_OK;
00180
00181 num = prev = 0;
00182 for (sfi = replaced; sfi->otherPkg; sfi++) {
00183 if (prev && prev == sfi->otherPkg)
00184 continue;
00185 prev = sfi->otherPkg;
00186 num++;
00187 }
00188 if (num == 0)
00189 return RPMRC_OK;
00190
00191 offsets = alloca(num * sizeof(*offsets));
00192 offsets[0] = 0;
00193 num = prev = 0;
00194 for (sfi = replaced; sfi->otherPkg; sfi++) {
00195 if (prev && prev == sfi->otherPkg)
00196 continue;
00197 prev = sfi->otherPkg;
00198 offsets[num++] = sfi->otherPkg;
00199 }
00200
00201 mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
00202 xx = rpmdbAppendIterator(mi, offsets, num);
00203 xx = rpmdbSetIteratorRewrite(mi, 1);
00204
00205 sfi = replaced;
00206 while ((h = rpmdbNextIterator(mi)) != NULL) {
00207 char * secStates;
00208 int modified;
00209 int count;
00210
00211 modified = 0;
00212
00213 if (!hge(h, RPMTAG_FILESTATES, NULL, (void **)&secStates, &count))
00214 continue;
00215
00216 prev = rpmdbGetIteratorOffset(mi);
00217 num = 0;
00218 while (sfi->otherPkg && sfi->otherPkg == prev) {
00219 assert(sfi->otherFileNum < count);
00220 if (secStates[sfi->otherFileNum] != RPMFILE_STATE_REPLACED) {
00221 secStates[sfi->otherFileNum] = RPMFILE_STATE_REPLACED;
00222 if (modified == 0) {
00223
00224 modified = 1;
00225 xx = rpmdbSetIteratorModified(mi, modified);
00226 }
00227 num++;
00228 }
00229 sfi++;
00230 }
00231 }
00232 mi = rpmdbFreeIterator(mi);
00233
00234 return RPMRC_OK;
00235 }
00236
00237
00238 rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd,
00239 const char ** specFilePtr, const char ** cookie)
00240 {
00241 int scareMem = 1;
00242 rpmfi fi = NULL;
00243 const char * _sourcedir = NULL;
00244 const char * _specdir = NULL;
00245 const char * specFile = NULL;
00246 HGE_t hge;
00247 HFD_t hfd;
00248 Header h = NULL;
00249 struct rpmpsm_s psmbuf;
00250 rpmpsm psm = &psmbuf;
00251 int isSource;
00252 rpmRC rpmrc;
00253 int i;
00254
00255 memset(psm, 0, sizeof(*psm));
00256 psm->ts = rpmtsLink(ts, "InstallSourcePackage");
00257
00258 rpmrc = rpmReadPackageFile(ts, fd, "InstallSourcePackage", &h);
00259 switch (rpmrc) {
00260 case RPMRC_NOTTRUSTED:
00261 case RPMRC_NOKEY:
00262 case RPMRC_OK:
00263 break;
00264 default:
00265 goto exit;
00266 break;
00267 }
00268 if (h == NULL)
00269 goto exit;
00270
00271 rpmrc = RPMRC_OK;
00272
00273 isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
00274
00275 if (!isSource) {
00276 rpmError(RPMERR_NOTSRPM, _("source package expected, binary found\n"));
00277 rpmrc = RPMRC_FAIL;
00278 goto exit;
00279 }
00280
00281 if (rpmtsAddInstallElement(ts, h, NULL, 0, NULL)) {
00282 rpmrc = RPMRC_FAIL;
00283 goto exit;
00284 }
00285
00286 fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
00287 h = headerFree(h);
00288
00289 if (fi == NULL) {
00290 rpmrc = RPMRC_FAIL;
00291 goto exit;
00292 }
00293
00294
00295 fi->te = rpmtsElement(ts, 0);
00296
00297 if (fi->te == NULL) {
00298 rpmrc = RPMRC_FAIL;
00299 goto exit;
00300 }
00301
00302
00303 fi->te->h = headerLink(fi->h);
00304
00305 fi->te->fd = fdLink(fd, "installSourcePackage");
00306 hge = fi->hge;
00307 hfd = fi->hfd;
00308
00309 (void) rpmInstallLoadMacros(fi, fi->h);
00310
00311 psm->fi = rpmfiLink(fi, NULL);
00312
00313 psm->te = fi->te;
00314
00315
00316 if (cookie) {
00317 *cookie = NULL;
00318 if (hge(fi->h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL))
00319 *cookie = xstrdup(*cookie);
00320 }
00321
00322
00323 fi->fmd5s = hfd(fi->fmd5s, -1);
00324
00325
00326 fi->fmapflags = _free(fi->fmapflags);
00327 fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
00328
00329 fi->uid = getuid();
00330 fi->gid = getgid();
00331 fi->astriplen = 0;
00332 fi->striplen = 0;
00333
00334 for (i = 0; i < fi->fc; i++)
00335 fi->actions[i] = FA_CREATE;
00336
00337 i = fi->fc;
00338
00339 if (fi->h != NULL) {
00340 rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
00341
00342 if (headerIsEntry(fi->h, RPMTAG_COOKIE))
00343 for (i = 0; i < fi->fc; i++)
00344 if (fi->fflags[i] & RPMFILE_SPECFILE) break;
00345 }
00346
00347 if (i == fi->fc) {
00348
00349 for (i = 0; i < fi->fc; i++) {
00350 const char * t = fi->apath[i];
00351 t += strlen(fi->apath[i]) - 5;
00352 if (!strcmp(t, ".spec")) break;
00353 }
00354 }
00355
00356 _sourcedir = rpmGenPath(rpmtsRootDir(ts), "%{_sourcedir}", "");
00357 rpmrc = rpmMkdirPath(_sourcedir, "sourcedir");
00358 if (rpmrc) {
00359 rpmrc = RPMRC_FAIL;
00360 goto exit;
00361 }
00362
00363 _specdir = rpmGenPath(rpmtsRootDir(ts), "%{_specdir}", "");
00364 rpmrc = rpmMkdirPath(_specdir, "specdir");
00365 if (rpmrc) {
00366 rpmrc = RPMRC_FAIL;
00367 goto exit;
00368 }
00369
00370
00371 if (i < fi->fc) {
00372 int speclen = strlen(_specdir) + 2;
00373 int sourcelen = strlen(_sourcedir) + 2;
00374 char * t;
00375
00376 fi->dnl = hfd(fi->dnl, -1);
00377
00378 fi->dc = 2;
00379 fi->dnl = xmalloc(fi->dc * sizeof(*fi->dnl)
00380 + fi->fc * sizeof(*fi->dil)
00381 + speclen + sourcelen);
00382
00383 fi->dil = (int *)(fi->dnl + fi->dc);
00384
00385 memset(fi->dil, 0, fi->fc * sizeof(*fi->dil));
00386 fi->dil[i] = 1;
00387
00388 fi->dnl[0] = t = (char *)(fi->dil + fi->fc);
00389 fi->dnl[1] = t = stpcpy( stpcpy(t, _sourcedir), "/") + 1;
00390
00391 (void) stpcpy( stpcpy(t, _specdir), "/");
00392
00393 t = xmalloc(speclen + strlen(fi->bnl[i]) + 1);
00394 (void) stpcpy( stpcpy( stpcpy(t, _specdir), "/"), fi->bnl[i]);
00395 specFile = t;
00396 } else {
00397 rpmError(RPMERR_NOSPEC, _("source package contains no .spec file\n"));
00398 rpmrc = RPMRC_FAIL;
00399 goto exit;
00400 }
00401
00402 psm->goal = PSM_PKGINSTALL;
00403
00404
00405 rpmrc = rpmpsmStage(psm, PSM_PROCESS);
00406
00407 (void) rpmpsmStage(psm, PSM_FINI);
00408
00409
00410 if (rpmrc) rpmrc = RPMRC_FAIL;
00411
00412 exit:
00413 if (specFilePtr && specFile && rpmrc == RPMRC_OK)
00414 *specFilePtr = specFile;
00415 else
00416 specFile = _free(specFile);
00417
00418 _specdir = _free(_specdir);
00419 _sourcedir = _free(_sourcedir);
00420
00421 psm->fi = rpmfiFree(psm->fi);
00422 psm->te = NULL;
00423
00424 if (h != NULL) h = headerFree(h);
00425
00426
00427 if (fi != NULL) {
00428 fi->te->h = headerFree(fi->te->h);
00429 if (fi->te->fd != NULL)
00430 (void) Fclose(fi->te->fd);
00431 fi->te->fd = NULL;
00432 fi->te = NULL;
00433 fi = rpmfiFree(fi);
00434 }
00435
00436
00437
00438 rpmtsClean(ts);
00439
00440 psm->ts = rpmtsFree(psm->ts);
00441
00442 return rpmrc;
00443 }
00444
00445
00446 static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin";
00447
00453 static const char * const tag2sln(int tag)
00454
00455 {
00456 switch (tag) {
00457 case RPMTAG_PRETRANS: return "%pretrans";
00458 case RPMTAG_PREIN: return "%pre";
00459 case RPMTAG_POSTIN: return "%post";
00460 case RPMTAG_TRIGGERIN: return "%triggerin";
00461 case RPMTAG_TRIGGERUN: return "%triggerun";
00462 case RPMTAG_PREUN: return "%preun";
00463 case RPMTAG_POSTUN: return "%postun";
00464 case RPMTAG_POSTTRANS: return "%posttrans";
00465 case RPMTAG_TRIGGERPOSTUN: return "%triggerpostun";
00466 case RPMTAG_VERIFYSCRIPT: return "%verify";
00467 }
00468 return "%unknownscript";
00469 }
00470
00476 static pid_t psmWait(rpmpsm psm)
00477
00478
00479 {
00480 const rpmts ts = psm->ts;
00481 rpmtime_t msecs;
00482
00483 (void) rpmsqWait(&psm->sq);
00484 msecs = psm->sq.op.usecs/1000;
00485 (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), &psm->sq.op);
00486
00487 rpmMessage(RPMMESS_DEBUG,
00488 _("%s: waitpid(%d) rc %d status %x secs %u.%03u\n"),
00489 psm->stepName, (unsigned)psm->sq.child,
00490 (unsigned)psm->sq.reaped, psm->sq.status,
00491 (unsigned)msecs/1000, (unsigned)msecs%1000);
00492
00493 return psm->sq.reaped;
00494 }
00495
00496 #ifdef WITH_LUA
00497
00500 static rpmRC runLuaScript(rpmpsm psm, Header h, const char *sln,
00501 int progArgc, const char **progArgv,
00502 const char *script, int arg1, int arg2)
00503
00504
00505 {
00506 const rpmts ts = psm->ts;
00507 int rootFd = -1;
00508 const char *n, *v, *r;
00509 rpmRC rc = RPMRC_OK;
00510 int i;
00511 int xx;
00512 rpmlua lua = NULL;
00513 rpmluav var;
00514
00515 xx = headerNVR(h, &n, &v, &r);
00516
00517 if (!rpmtsChrootDone(ts)) {
00518 const char *rootDir = rpmtsRootDir(ts);
00519 xx = chdir("/");
00520
00521 rootFd = open(".", O_RDONLY, 0);
00522
00523 if (rootFd >= 0) {
00524
00525 if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
00526 xx = chroot(rootDir);
00527
00528 xx = rpmtsSetChrootDone(ts, 1);
00529 }
00530 }
00531
00532
00533 rpmluaPushTable(lua, "arg");
00534 var = rpmluavNew();
00535 rpmluavSetListMode(var, 1);
00536
00537 if (progArgv) {
00538 for (i = 0; i < progArgc && progArgv[i]; i++) {
00539 rpmluavSetValue(var, RPMLUAV_STRING, progArgv[i]);
00540 rpmluaSetVar(lua, var);
00541 }
00542 }
00543 if (arg1 >= 0) {
00544 rpmluavSetValueNum(var, arg1);
00545 rpmluaSetVar(lua, var);
00546 }
00547 if (arg2 >= 0) {
00548 rpmluavSetValueNum(var, arg2);
00549 rpmluaSetVar(lua, var);
00550 }
00551
00552
00553 var = rpmluavFree(var);
00554
00555 rpmluaPop(lua);
00556
00557 {
00558 char buf[BUFSIZ];
00559 xx = snprintf(buf, BUFSIZ, "%s(%s-%s-%s)", sln, n, v, r);
00560 if (rpmluaRunScript(lua, script, buf) == -1)
00561 rc = RPMRC_FAIL;
00562 }
00563
00564 rpmluaDelVar(lua, "arg");
00565
00566 if (rootFd >= 0) {
00567 const char *rootDir = rpmtsRootDir(ts);
00568 xx = fchdir(rootFd);
00569 xx = close(rootFd);
00570
00571 if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
00572 xx = chroot(".");
00573
00574 xx = rpmtsSetChrootDone(ts, 0);
00575 }
00576
00577 return rc;
00578 }
00579 #endif
00580
00583
00584 static int ldconfig_done = 0;
00585
00586
00587 static const char * ldconfig_path = "/sbin/ldconfig";
00588
00607 static rpmRC runScript(rpmpsm psm, Header h, const char * sln,
00608 int progArgc, const char ** progArgv,
00609 const char * script, int arg1, int arg2)
00610
00611
00612
00613
00614 {
00615 const rpmts ts = psm->ts;
00616 rpmfi fi = psm->fi;
00617 HGE_t hge = fi->hge;
00618 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00619 const char ** argv = NULL;
00620 int argc = 0;
00621 const char ** prefixes = NULL;
00622 int numPrefixes;
00623 rpmTagType ipt;
00624 const char * oldPrefix;
00625 int maxPrefixLength;
00626 int len;
00627 char * prefixBuf = NULL;
00628 const char * fn = NULL;
00629 int xx;
00630 int i;
00631 int freePrefixes = 0;
00632 FD_t scriptFd;
00633 FD_t out;
00634 rpmRC rc = RPMRC_OK;
00635 const char *n, *v, *r, *a;
00636
00637 if (progArgv == NULL && script == NULL)
00638 return rc;
00639
00640
00641 xx = headerNVR(h, &n, &v, &r);
00642 xx = hge(h, RPMTAG_ARCH, NULL, (void **) &a, NULL);
00643
00644 if (progArgv && strcmp(progArgv[0], "<lua>") == 0) {
00645 #ifdef WITH_LUA
00646 rpmMessage(RPMMESS_DEBUG,
00647 _("%s: %s(%s-%s-%s.%s) running <lua> scriptlet.\n"),
00648 psm->stepName, tag2sln(psm->scriptTag), n, v, r, a);
00649 return runLuaScript(psm, h, sln, progArgc, progArgv,
00650 script, arg1, arg2);
00651 #else
00652 return RPMRC_FAIL;
00653 #endif
00654 }
00655
00656 psm->sq.reaper = 1;
00657
00658
00659
00660
00661 if (ldconfig_path && progArgv != NULL && psm->unorderedSuccessor) {
00662 if (ldconfig_done && !strcmp(progArgv[0], ldconfig_path)) {
00663 rpmMessage(RPMMESS_DEBUG,
00664 _("%s: %s(%s-%s-%s.%s) skipping redundant \"%s\".\n"),
00665 psm->stepName, tag2sln(psm->scriptTag), n, v, r, a,
00666 progArgv[0]);
00667 return rc;
00668 }
00669 }
00670
00671 rpmMessage(RPMMESS_DEBUG,
00672 _("%s: %s(%s-%s-%s.%s) %ssynchronous scriptlet start\n"),
00673 psm->stepName, tag2sln(psm->scriptTag), n, v, r, a,
00674 (psm->unorderedSuccessor ? "a" : ""));
00675
00676 if (!progArgv) {
00677 argv = alloca(5 * sizeof(*argv));
00678 argv[0] = "/bin/sh";
00679 argc = 1;
00680 ldconfig_done = 0;
00681 } else {
00682 argv = alloca((progArgc + 4) * sizeof(*argv));
00683 memcpy(argv, progArgv, progArgc * sizeof(*argv));
00684 argc = progArgc;
00685 ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path)
00686 ? 1 : 0);
00687 }
00688
00689 #if __ia64__
00690
00691 if ((a != NULL && a[0] == 'i' && a[1] != '\0' && a[2] == '8' && a[3] == '6')
00692 && strcmp(argv[0], "/sbin/ldconfig"))
00693 {
00694 const char * fmt = rpmGetPath("%{?_autorelocate_path}", NULL);
00695 const char * errstr;
00696 char * newPath;
00697 char * t;
00698
00699 newPath = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
00700 fmt = _free(fmt);
00701
00702
00703 if (newPath != NULL && *newPath != '\0'
00704 && strlen(newPath) >= (sizeof("/emul/i386")-1)
00705 && newPath[0] == '/' && newPath[1] == 'e' && newPath[2] == 'm'
00706 && newPath[3] == 'u' && newPath[4] == 'l' && newPath[5] == '/'
00707 && newPath[6] == 'i' && newPath[8] == '8' && newPath[9] == '6')
00708 {
00709 newPath[7] = 'a';
00710 newPath[8] = '3';
00711 newPath[9] = '2';
00712 }
00713
00714 t = alloca(strlen(newPath) + strlen(argv[0]) + 1);
00715 *t = '\0';
00716 (void) stpcpy( stpcpy(t, newPath), argv[0]);
00717 newPath = _free(newPath);
00718 argv[0] = t;
00719 }
00720 #endif
00721
00722 if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &prefixes, &numPrefixes)) {
00723 freePrefixes = 1;
00724 } else if (hge(h, RPMTAG_INSTALLPREFIX, NULL, (void **) &oldPrefix, NULL)) {
00725 prefixes = &oldPrefix;
00726 numPrefixes = 1;
00727 } else {
00728 numPrefixes = 0;
00729 }
00730
00731 maxPrefixLength = 0;
00732 if (prefixes != NULL)
00733 for (i = 0; i < numPrefixes; i++) {
00734 len = strlen(prefixes[i]);
00735 if (len > maxPrefixLength) maxPrefixLength = len;
00736 }
00737 prefixBuf = alloca(maxPrefixLength + 50);
00738
00739 if (script) {
00740 const char * rootDir = rpmtsRootDir(ts);
00741 FD_t fd;
00742
00743
00744 if (makeTempFile((!rpmtsChrootDone(ts) ? rootDir : "/"), &fn, &fd)) {
00745 if (prefixes != NULL && freePrefixes) free(prefixes);
00746 return RPMRC_FAIL;
00747 }
00748
00749
00750 if (rpmIsDebug() &&
00751 (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
00752 {
00753 static const char set_x[] = "set -x\n";
00754 xx = Fwrite(set_x, sizeof(set_x[0]), sizeof(set_x)-1, fd);
00755 }
00756
00757 if (ldconfig_path && strstr(script, ldconfig_path) != NULL)
00758 ldconfig_done = 1;
00759
00760 xx = Fwrite(script, sizeof(script[0]), strlen(script), fd);
00761 xx = Fclose(fd);
00762
00763 { const char * sn = fn;
00764 if (!rpmtsChrootDone(ts) && rootDir != NULL &&
00765 !(rootDir[0] == '/' && rootDir[1] == '\0'))
00766 {
00767 sn += strlen(rootDir)-1;
00768 }
00769 argv[argc++] = sn;
00770 }
00771
00772 if (arg1 >= 0) {
00773 char *av = alloca(20);
00774 sprintf(av, "%d", arg1);
00775 argv[argc++] = av;
00776 }
00777 if (arg2 >= 0) {
00778 char *av = alloca(20);
00779 sprintf(av, "%d", arg2);
00780 argv[argc++] = av;
00781 }
00782 }
00783
00784 argv[argc] = NULL;
00785
00786 scriptFd = rpmtsScriptFd(ts);
00787 if (scriptFd != NULL) {
00788 if (rpmIsVerbose()) {
00789 out = fdDup(Fileno(scriptFd));
00790 } else {
00791 out = Fopen("/dev/null", "w.fdio");
00792 if (Ferror(out)) {
00793 out = fdDup(Fileno(scriptFd));
00794 }
00795 }
00796 } else {
00797 out = fdDup(STDOUT_FILENO);
00798 }
00799 if (out == NULL) return RPMRC_FAIL;
00800
00801
00802 xx = rpmsqFork(&psm->sq);
00803 if (psm->sq.child == 0) {
00804 const char * rootDir;
00805 int pipes[2];
00806 int flag;
00807 int fdno;
00808
00809 pipes[0] = pipes[1] = 0;
00810
00811 xx = pipe(pipes);
00812 xx = close(pipes[1]);
00813 xx = dup2(pipes[0], STDIN_FILENO);
00814 xx = close(pipes[0]);
00815
00816
00817 for (fdno = 3; fdno < 100; fdno++) {
00818 flag = fcntl(fdno, F_GETFD);
00819 if (flag == -1 || (flag & FD_CLOEXEC))
00820 continue;
00821 xx = fcntl(fdno, F_SETFD, FD_CLOEXEC);
00822
00823 }
00824
00825 if (scriptFd != NULL) {
00826 int sfdno = Fileno(scriptFd);
00827 int ofdno = Fileno(out);
00828 if (sfdno != STDERR_FILENO)
00829 xx = dup2(sfdno, STDERR_FILENO);
00830 if (ofdno != STDOUT_FILENO)
00831 xx = dup2(ofdno, STDOUT_FILENO);
00832
00833 if (ofdno > STDERR_FILENO && ofdno != sfdno)
00834 xx = Fclose (out);
00835 if (sfdno > STDERR_FILENO && ofdno != sfdno)
00836 xx = Fclose (scriptFd);
00837 }
00838
00839 { const char *ipath = rpmExpand("PATH=%{_install_script_path}", NULL);
00840 const char *path = SCRIPT_PATH;
00841
00842 if (ipath && ipath[5] != '%')
00843 path = ipath;
00844
00845 xx = doputenv(path);
00846
00847 ipath = _free(ipath);
00848
00849 }
00850
00851 if (prefixes != NULL)
00852 for (i = 0; i < numPrefixes; i++) {
00853 sprintf(prefixBuf, "RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
00854 xx = doputenv(prefixBuf);
00855
00856
00857 if (i == 0) {
00858 sprintf(prefixBuf, "RPM_INSTALL_PREFIX=%s", prefixes[i]);
00859 xx = doputenv(prefixBuf);
00860 }
00861 }
00862
00863 rootDir = ts->rootDir;
00864 if (rootDir != NULL)
00865 switch(urlIsURL(rootDir)) {
00866 case URL_IS_PATH:
00867 rootDir += sizeof("file://") - 1;
00868 rootDir = strchr(rootDir, '/');
00869
00870 case URL_IS_UNKNOWN:
00871 if (!rpmtsChrootDone(ts) &&
00872 !(rootDir[0] == '/' && rootDir[1] == '\0'))
00873 {
00874
00875 xx = chroot(rootDir);
00876
00877 }
00878 xx = chdir("/");
00879 rpmMessage(RPMMESS_DEBUG, _("%s: %s(%s-%s-%s.%s)\texecv(%s) pid %d\n"),
00880 psm->stepName, sln, n, v, r, a,
00881 argv[0], (unsigned)getpid());
00882
00883
00884 unsetenv("MALLOC_CHECK_");
00885
00886
00887 if (rpmtsSELinuxEnabled(ts) == 1) {
00888
00889 xx = rpm_execcon(0, argv[0], argv, environ);
00890
00891 if (xx != 0)
00892 break;
00893 }
00894
00895
00896 xx = execv(argv[0], (char *const *)argv);
00897
00898 break;
00899 case URL_IS_HTTPS:
00900 case URL_IS_HTTP:
00901 case URL_IS_FTP:
00902 case URL_IS_DASH:
00903 case URL_IS_HKP:
00904 default:
00905 break;
00906 }
00907
00908 _exit(-1);
00909
00910 }
00911
00912
00913 if (psm->sq.child == (pid_t)-1) {
00914 rpmError(RPMERR_FORK, _("Couldn't fork %s: %s\n"), sln, strerror(errno));
00915 rc = RPMRC_FAIL;
00916 goto exit;
00917 }
00918
00919 (void) psmWait(psm);
00920
00921
00922 if (!(psm->sq.reaped >= 0 && !strcmp(argv[0], "/usr/sbin/glibc_post_upgrade") && WEXITSTATUS(psm->sq.status) == 110)) {
00923 if (psm->sq.reaped < 0) {
00924 rpmError(RPMERR_SCRIPT,
00925 _("%s(%s-%s-%s.%s) scriptlet failed, waitpid(%d) rc %d: %s\n"),
00926 sln, n, v, r, a, psm->sq.child, psm->sq.reaped, strerror(errno));
00927 rc = RPMRC_FAIL;
00928 } else
00929 if (!WIFEXITED(psm->sq.status) || WEXITSTATUS(psm->sq.status)) {
00930 if (WIFSIGNALED(psm->sq.status)) {
00931 rpmError(RPMERR_SCRIPT,
00932 _("%s(%s-%s-%s.%s) scriptlet failed, signal %d\n"),
00933 sln, n, v, r, a, WTERMSIG(psm->sq.status));
00934 } else {
00935 rpmError(RPMERR_SCRIPT,
00936 _("%s(%s-%s-%s.%s) scriptlet failed, exit status %d\n"),
00937 sln, n, v, r, a, WEXITSTATUS(psm->sq.status));
00938 }
00939 rc = RPMRC_FAIL;
00940 }
00941 }
00942
00943 exit:
00944 if (freePrefixes) prefixes = hfd(prefixes, ipt);
00945
00946 xx = Fclose(out);
00947
00948
00949 if (script) {
00950 if (!rpmIsDebug())
00951 xx = unlink(fn);
00952 fn = _free(fn);
00953 }
00954
00955
00956 return rc;
00957 }
00958
00964 static rpmRC runInstScript(rpmpsm psm)
00965
00966
00967 {
00968 rpmfi fi = psm->fi;
00969 HGE_t hge = fi->hge;
00970 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00971 void ** progArgv;
00972 int progArgc;
00973 const char ** argv;
00974 rpmTagType ptt, stt;
00975 const char * script;
00976 rpmRC rc = RPMRC_OK;
00977 int xx;
00978
00979
00980
00981
00982
00983 xx = hge(fi->h, psm->scriptTag, &stt, (void **) &script, NULL);
00984 xx = hge(fi->h, psm->progTag, &ptt, (void **) &progArgv, &progArgc);
00985 if (progArgv == NULL && script == NULL)
00986 goto exit;
00987
00988
00989 if (progArgv && ptt == RPM_STRING_TYPE) {
00990 argv = alloca(sizeof(*argv));
00991 *argv = (const char *) progArgv;
00992 } else {
00993 argv = (const char **) progArgv;
00994 }
00995
00996
00997 if (fi->h != NULL)
00998 rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), progArgc, argv,
00999 script, psm->scriptArg, -1);
01000
01001 exit:
01002 progArgv = hfd(progArgv, ptt);
01003 script = hfd(script, stt);
01004 return rc;
01005 }
01006
01017 static rpmRC handleOneTrigger(const rpmpsm psm,
01018 Header sourceH, Header triggeredH,
01019 int arg2, unsigned char * triggersAlreadyRun)
01020
01021
01022
01023 {
01024 int scareMem = 1;
01025 const rpmts ts = psm->ts;
01026 rpmfi fi = psm->fi;
01027 HGE_t hge = fi->hge;
01028 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
01029 rpmds trigger = NULL;
01030 const char ** triggerScripts;
01031 const char ** triggerProgs;
01032 int_32 * triggerIndices;
01033 const char * sourceName;
01034 const char * triggerName;
01035 rpmRC rc = RPMRC_OK;
01036 int xx;
01037 int i;
01038
01039 xx = headerNVR(sourceH, &sourceName, NULL, NULL);
01040 xx = headerNVR(triggeredH, &triggerName, NULL, NULL);
01041
01042 trigger = rpmdsInit(rpmdsNew(triggeredH, RPMTAG_TRIGGERNAME, scareMem));
01043 if (trigger == NULL)
01044 return rc;
01045
01046 (void) rpmdsSetNoPromote(trigger, 1);
01047
01048 while ((i = rpmdsNext(trigger)) >= 0) {
01049 rpmTagType tit, tst, tpt;
01050 const char * Name;
01051 int_32 Flags = rpmdsFlags(trigger);
01052
01053 if ((Name = rpmdsN(trigger)) == NULL)
01054 continue;
01055
01056 if (strcmp(Name, sourceName))
01057 continue;
01058 if (!(Flags & psm->sense))
01059 continue;
01060
01061
01062
01063
01064 if (!rpmdsAnyMatchesDep(sourceH, trigger, 1))
01065 continue;
01066
01067 if (!( hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit,
01068 (void **) &triggerIndices, NULL) &&
01069 hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst,
01070 (void **) &triggerScripts, NULL) &&
01071 hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt,
01072 (void **) &triggerProgs, NULL))
01073 )
01074 continue;
01075
01076 { int arg1;
01077 int index;
01078
01079 arg1 = rpmdbCountPackages(rpmtsGetRdb(ts), triggerName);
01080 if (arg1 < 0) {
01081
01082 rc = RPMRC_FAIL;
01083 } else {
01084 arg1 += psm->countCorrection;
01085 index = triggerIndices[i];
01086 if (triggersAlreadyRun == NULL ||
01087 triggersAlreadyRun[index] == 0)
01088 {
01089 rc = runScript(psm, triggeredH, "%trigger", 1,
01090 triggerProgs + index, triggerScripts[index],
01091 arg1, arg2);
01092 if (triggersAlreadyRun != NULL)
01093 triggersAlreadyRun[index] = 1;
01094 }
01095 }
01096 }
01097
01098 triggerIndices = hfd(triggerIndices, tit);
01099 triggerScripts = hfd(triggerScripts, tst);
01100 triggerProgs = hfd(triggerProgs, tpt);
01101
01102
01103
01104
01105
01106 break;
01107 }
01108
01109 trigger = rpmdsFree(trigger);
01110
01111 return rc;
01112 }
01113
01119 static rpmRC runTriggers(rpmpsm psm)
01120
01121
01122
01123
01124 {
01125 const rpmts ts = psm->ts;
01126 rpmfi fi = psm->fi;
01127 int numPackage = -1;
01128 rpmRC rc = RPMRC_OK;
01129 const char * N = NULL;
01130
01131 if (psm->te)
01132 N = rpmteN(psm->te);
01133
01134 if (N)
01135 numPackage = rpmdbCountPackages(rpmtsGetRdb(ts), N)
01136 + psm->countCorrection;
01137 if (numPackage < 0)
01138 return RPMRC_NOTFOUND;
01139
01140 if (fi != NULL && fi->h != NULL)
01141 { Header triggeredH;
01142 rpmdbMatchIterator mi;
01143 int countCorrection = psm->countCorrection;
01144
01145 psm->countCorrection = 0;
01146 mi = rpmtsInitIterator(ts, RPMTAG_TRIGGERNAME, N, 0);
01147 while((triggeredH = rpmdbNextIterator(mi)) != NULL)
01148 rc |= handleOneTrigger(psm, fi->h, triggeredH, numPackage, NULL);
01149 mi = rpmdbFreeIterator(mi);
01150 psm->countCorrection = countCorrection;
01151 }
01152
01153 return rc;
01154 }
01155
01161 static rpmRC runImmedTriggers(rpmpsm psm)
01162
01163
01164
01165
01166 {
01167 const rpmts ts = psm->ts;
01168 rpmfi fi = psm->fi;
01169 HGE_t hge = fi->hge;
01170 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
01171 const char ** triggerNames;
01172 int numTriggers;
01173 int_32 * triggerIndices;
01174 rpmTagType tnt, tit;
01175 int numTriggerIndices;
01176 unsigned char * triggersRun;
01177 rpmRC rc = RPMRC_OK;
01178
01179 if (fi->h == NULL) return rc;
01180
01181 if (!( hge(fi->h, RPMTAG_TRIGGERNAME, &tnt,
01182 (void **) &triggerNames, &numTriggers) &&
01183 hge(fi->h, RPMTAG_TRIGGERINDEX, &tit,
01184 (void **) &triggerIndices, &numTriggerIndices))
01185 )
01186 return rc;
01187
01188 triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
01189 memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
01190
01191 { Header sourceH = NULL;
01192 int i;
01193
01194 for (i = 0; i < numTriggers; i++) {
01195 rpmdbMatchIterator mi;
01196
01197 if (triggersRun[triggerIndices[i]] != 0) continue;
01198
01199 mi = rpmtsInitIterator(ts, RPMTAG_NAME, triggerNames[i], 0);
01200
01201 while((sourceH = rpmdbNextIterator(mi)) != NULL) {
01202 rc |= handleOneTrigger(psm, sourceH, fi->h,
01203 rpmdbGetIteratorCount(mi),
01204 triggersRun);
01205 }
01206
01207 mi = rpmdbFreeIterator(mi);
01208 }
01209 }
01210 triggerIndices = hfd(triggerIndices, tit);
01211 triggerNames = hfd(triggerNames, tnt);
01212 return rc;
01213 }
01214
01215 static const char *const pkgStageString(pkgStage a)
01216
01217 {
01218 switch(a) {
01219 case PSM_UNKNOWN: return "unknown";
01220
01221 case PSM_PKGINSTALL: return " install";
01222 case PSM_PKGERASE: return " erase";
01223 case PSM_PKGCOMMIT: return " commit";
01224 case PSM_PKGSAVE: return "repackage";
01225
01226 case PSM_INIT: return "init";
01227 case PSM_PRE: return "pre";
01228 case PSM_PROCESS: return "process";
01229 case PSM_POST: return "post";
01230 case PSM_UNDO: return "undo";
01231 case PSM_FINI: return "fini";
01232
01233 case PSM_CREATE: return "create";
01234 case PSM_NOTIFY: return "notify";
01235 case PSM_DESTROY: return "destroy";
01236 case PSM_COMMIT: return "commit";
01237
01238 case PSM_CHROOT_IN: return "chrootin";
01239 case PSM_CHROOT_OUT: return "chrootout";
01240 case PSM_SCRIPT: return "script";
01241 case PSM_TRIGGERS: return "triggers";
01242 case PSM_IMMED_TRIGGERS: return "immedtriggers";
01243
01244 case PSM_RPMIO_FLAGS: return "rpmioflags";
01245
01246 case PSM_RPMDB_LOAD: return "rpmdbload";
01247 case PSM_RPMDB_ADD: return "rpmdbadd";
01248 case PSM_RPMDB_REMOVE: return "rpmdbremove";
01249
01250 default: return "???";
01251 }
01252
01253 }
01254
01255 rpmpsm XrpmpsmUnlink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
01256 {
01257 if (psm == NULL) return NULL;
01258
01259 if (_psm_debug && msg != NULL)
01260 fprintf(stderr, "--> psm %p -- %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
01261
01262 psm->nrefs--;
01263 return NULL;
01264 }
01265
01266 rpmpsm XrpmpsmLink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
01267 {
01268 if (psm == NULL) return NULL;
01269 psm->nrefs++;
01270
01271
01272 if (_psm_debug && msg != NULL)
01273 fprintf(stderr, "--> psm %p ++ %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
01274
01275
01276 return psm;
01277 }
01278
01279 rpmpsm rpmpsmFree(rpmpsm psm)
01280 {
01281 const char * msg = "rpmpsmFree";
01282 if (psm == NULL)
01283 return NULL;
01284
01285 if (psm->nrefs > 1)
01286 return rpmpsmUnlink(psm, msg);
01287
01288
01289 psm->fi = rpmfiFree(psm->fi);
01290 #ifdef NOTYET
01291 psm->te = rpmteFree(psm->te);
01292 #else
01293 psm->te = NULL;
01294 #endif
01295
01296 psm->ts = rpmtsFree(psm->ts);
01297
01298
01299 (void) rpmpsmUnlink(psm, msg);
01300
01301
01302
01303 memset(psm, 0, sizeof(*psm));
01304
01305 psm = _free(psm);
01306
01307
01308 return NULL;
01309
01310 }
01311
01312 rpmpsm rpmpsmNew(rpmts ts, rpmte te, rpmfi fi)
01313 {
01314 const char * msg = "rpmpsmNew";
01315 rpmpsm psm = xcalloc(1, sizeof(*psm));
01316
01317 if (ts) psm->ts = rpmtsLink(ts, msg);
01318 #ifdef NOTYET
01319 if (te) psm->te = rpmteLink(te, msg);
01320 #else
01321
01322 if (te) psm->te = te;
01323
01324 #endif
01325 if (fi) psm->fi = rpmfiLink(fi, msg);
01326
01327 return rpmpsmLink(psm, msg);
01328 }
01329
01330 static void * rpmpsmThread(void * arg)
01331
01332
01333 {
01334 rpmpsm psm = arg;
01335
01336 return ((void *) rpmpsmStage(psm, psm->nstage));
01337
01338 }
01339
01340 static int rpmpsmNext(rpmpsm psm, pkgStage nstage)
01341
01342
01343 {
01344 psm->nstage = nstage;
01345 if (_psm_threads)
01346 return rpmsqJoin( rpmsqThread(rpmpsmThread, psm) );
01347 return rpmpsmStage(psm, psm->nstage);
01348 }
01349
01354
01355 rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
01356 {
01357 const rpmts ts = psm->ts;
01358 uint_32 tscolor = rpmtsColor(ts);
01359 rpmfi fi = psm->fi;
01360 HGE_t hge = fi->hge;
01361 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
01362 rpmRC rc = psm->rc;
01363 int saveerrno;
01364 int xx;
01365
01366
01367 switch (stage) {
01368 case PSM_UNKNOWN:
01369 break;
01370 case PSM_INIT:
01371 rpmMessage(RPMMESS_DEBUG, _("%s: %s has %d files, test = %d\n"),
01372 psm->stepName, rpmteNEVR(psm->te),
01373 rpmfiFC(fi), (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST));
01374
01375
01376
01377
01378
01379
01380 psm->npkgs_installed = rpmdbCountPackages(rpmtsGetRdb(ts), rpmteN(psm->te));
01381 if (psm->npkgs_installed < 0) {
01382 rc = RPMRC_FAIL;
01383 break;
01384 }
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395 if (rpmtsGetScore(ts) != NULL &&
01396 rpmtsGetType(ts) == RPMTRANS_TYPE_AUTOROLLBACK &&
01397 (psm->goal & ~(PSM_PKGSAVE|PSM_PKGERASE))) {
01398
01399
01400
01401 rpmtsScore score = rpmtsGetScore(ts);
01402 if (score != NULL) {
01403
01404
01405
01406 rpmtsScoreEntry se;
01407 se = rpmtsScoreGetEntry(score, rpmteN(psm->te));
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421 if (se && se->installed &&
01422 !se->erased &&
01423 (se->te_types & (TR_ADDED|TR_REMOVED)))
01424 psm->npkgs_installed--;
01425 }
01426 }
01427
01428 if (psm->goal == PSM_PKGINSTALL) {
01429 int fc = rpmfiFC(fi);
01430
01431 psm->scriptArg = psm->npkgs_installed + 1;
01432
01433 assert(psm->mi == NULL);
01434 psm->mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(psm->te), 0);
01435 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_EPOCH, RPMMIRE_STRCMP,
01436 rpmteE(psm->te));
01437 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_VERSION, RPMMIRE_STRCMP,
01438 rpmteV(psm->te));
01439 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_RELEASE, RPMMIRE_STRCMP,
01440 rpmteR(psm->te));
01441 if (tscolor) {
01442 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_ARCH, RPMMIRE_STRCMP,
01443 rpmteA(psm->te));
01444 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_OS, RPMMIRE_STRCMP,
01445 rpmteO(psm->te));
01446 }
01447
01448 while ((psm->oh = rpmdbNextIterator(psm->mi)) != NULL) {
01449 fi->record = rpmdbGetIteratorOffset(psm->mi);
01450 psm->oh = NULL;
01451 break;
01452 }
01453 psm->mi = rpmdbFreeIterator(psm->mi);
01454 rc = RPMRC_OK;
01455
01456
01457 if (fi->fstates == NULL && fc > 0) {
01458 fi->fstates = xmalloc(sizeof(*fi->fstates) * fc);
01459 memset(fi->fstates, RPMFILE_STATE_NORMAL, fc);
01460 }
01461
01462 if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
01463 if (fc <= 0) break;
01464
01465
01466
01467
01468
01469
01470 { const char * p;
01471 xx = hge(fi->h, RPMTAG_DEFAULTPREFIX, NULL, (void **) &p, NULL);
01472 fi->striplen = (xx ? strlen(p) + 1 : 1);
01473 }
01474 fi->mapflags =
01475 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID | (fi->mapflags & CPIO_SBIT_CHECK);
01476
01477 if (headerIsEntry(fi->h, RPMTAG_ORIGBASENAMES))
01478 rpmfiBuildFNames(fi->h, RPMTAG_ORIGBASENAMES, &fi->apath, NULL);
01479 else
01480 rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
01481
01482 if (fi->fuser == NULL)
01483 xx = hge(fi->h, RPMTAG_FILEUSERNAME, NULL,
01484 (void **) &fi->fuser, NULL);
01485 if (fi->fgroup == NULL)
01486 xx = hge(fi->h, RPMTAG_FILEGROUPNAME, NULL,
01487 (void **) &fi->fgroup, NULL);
01488 rc = RPMRC_OK;
01489 }
01490 if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
01491 psm->scriptArg = psm->npkgs_installed - 1;
01492
01493
01494 rc = rpmpsmNext(psm, PSM_RPMDB_LOAD);
01495 if (rc == RPMRC_OK)
01496 if (psm->te)
01497 psm->te->h = headerLink(fi->h);
01498 }
01499 if (psm->goal == PSM_PKGSAVE) {
01500
01501 { const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL);
01502 const char * pkgbn =
01503 headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL);
01504
01505 bfmt = _free(bfmt);
01506 psm->pkgURL = rpmGenPath("%{?_repackage_root}",
01507 "%{?_repackage_dir}",
01508 pkgbn);
01509 pkgbn = _free(pkgbn);
01510 (void) urlPath(psm->pkgURL, &psm->pkgfn);
01511 psm->fd = Fopen(psm->pkgfn, "w.ufdio");
01512 if (psm->fd == NULL || Ferror(psm->fd)) {
01513 rc = RPMRC_FAIL;
01514 break;
01515 }
01516 }
01517 }
01518 break;
01519 case PSM_PRE:
01520 if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
01521
01522
01523 #ifdef NOTYET
01524 { static int oneshot = 0;
01525 dbiIndex dbi;
01526 if (!oneshot) {
01527 dbi = dbiOpen(rpmtsGetRdb(ts), RPMTAG_TRIGGERNAME, 0);
01528 oneshot++;
01529 }
01530 }
01531 #endif
01532
01533
01534 rc = rpmpsmNext(psm, PSM_CHROOT_IN);
01535
01536 if (psm->goal == PSM_PKGINSTALL) {
01537 psm->scriptTag = RPMTAG_PREIN;
01538 psm->progTag = RPMTAG_PREINPROG;
01539
01540 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPREIN)) {
01541
01542 }
01543
01544 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPRE)) {
01545 rc = rpmpsmNext(psm, PSM_SCRIPT);
01546 if (rc != RPMRC_OK) {
01547 rpmError(RPMERR_SCRIPT,
01548 _("%s: %s scriptlet failed (%d), skipping %s\n"),
01549 psm->stepName, tag2sln(psm->scriptTag), rc,
01550 rpmteNEVR(psm->te));
01551 break;
01552 }
01553 }
01554 }
01555
01556 if (psm->goal == PSM_PKGERASE) {
01557 psm->scriptTag = RPMTAG_PREUN;
01558 psm->progTag = RPMTAG_PREUNPROG;
01559 psm->sense = RPMSENSE_TRIGGERUN;
01560 psm->countCorrection = -1;
01561
01562 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERUN)) {
01563
01564 rc = rpmpsmNext(psm, PSM_IMMED_TRIGGERS);
01565 if (rc) break;
01566
01567
01568 rc = rpmpsmNext(psm, PSM_TRIGGERS);
01569 if (rc) break;
01570 }
01571
01572 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPREUN))
01573 rc = rpmpsmNext(psm, PSM_SCRIPT);
01574 }
01575 if (psm->goal == PSM_PKGSAVE) {
01576 int noArchiveSize = 0;
01577
01578
01579 { void * uh = NULL;
01580 int_32 uht, uhc;
01581
01582 if (headerGetEntry(fi->h, RPMTAG_HEADERIMMUTABLE, &uht, &uh, &uhc)) {
01583 psm->oh = headerCopyLoad(uh);
01584 uh = hfd(uh, uht);
01585 } else
01586 if (headerGetEntry(fi->h, RPMTAG_HEADERIMAGE, &uht, &uh, &uhc))
01587 {
01588 HeaderIterator hi;
01589 int_32 tag, type, count;
01590 hPTR_t ptr;
01591 Header oh;
01592
01593
01594 oh = headerCopyLoad(uh);
01595
01596
01597 psm->oh = headerNew();
01598
01599
01600 for (hi = headerInitIterator(oh);
01601 headerNextIterator(hi, &tag, &type, &ptr, &count);
01602 ptr = headerFreeData((void *)ptr, type))
01603 {
01604 if (tag == RPMTAG_ARCHIVESIZE)
01605 noArchiveSize = 1;
01606 if (ptr) (void) headerAddEntry(psm->oh, tag, type, ptr, count);
01607 }
01608 hi = headerFreeIterator(hi);
01609
01610
01611 oh = headerFree(oh);
01612 uh = hfd(uh, uht);
01613 } else
01614 break;
01615 }
01616
01617
01618
01619 rc = rpmpsmNext(psm, PSM_RPMIO_FLAGS);
01620
01621
01622
01623 { int archnum = -1;
01624 int osnum = -1;
01625 struct rpmlead lead;
01626
01627 #ifndef DYING
01628 rpmGetArchInfo(NULL, &archnum);
01629 rpmGetOsInfo(NULL, &osnum);
01630 #endif
01631
01632 memset(&lead, 0, sizeof(lead));
01633
01634 lead.major = 3;
01635 lead.minor = 0;
01636 lead.type = RPMLEAD_BINARY;
01637 lead.archnum = archnum;
01638 lead.osnum = osnum;
01639 lead.signature_type = RPMSIGTYPE_HEADERSIG;
01640
01641 strncpy(lead.name, rpmteNEVR(psm->te), sizeof(lead.name));
01642
01643 rc = writeLead(psm->fd, &lead);
01644 if (rc != RPMRC_OK) {
01645 rpmError(RPMERR_NOSPACE, _("Unable to write package: %s\n"),
01646 Fstrerror(psm->fd));
01647 break;
01648 }
01649 }
01650
01651
01652
01653 { Header sigh = headerRegenSigHeader(fi->h, noArchiveSize);
01654
01655 sigh = headerReload(sigh, RPMTAG_HEADERSIGNATURES);
01656 if (sigh == NULL) {
01657 rpmError(RPMERR_NOSPACE, _("Unable to reload signature header\n"));
01658 rc = RPMRC_FAIL;
01659 break;
01660 }
01661 rc = rpmWriteSignature(psm->fd, sigh);
01662 sigh = rpmFreeSignature(sigh);
01663 if (rc) break;
01664 }
01665
01666
01667 if (psm->oh != NULL)
01668 { int_32 tid = rpmtsGetTid(ts);
01669 xx = headerAddEntry(psm->oh, RPMTAG_REMOVETID,
01670 RPM_INT32_TYPE, &tid, 1);
01671 }
01672
01673
01674 rc = headerWrite(psm->fd, psm->oh, HEADER_MAGIC_YES);
01675 if (rc) break;
01676 }
01677 break;
01678 case PSM_PROCESS:
01679 if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
01680
01681 if (psm->goal == PSM_PKGINSTALL) {
01682
01683 if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
01684
01685
01686 if (rpmfiFC(fi) <= 0) {
01687 void * ptr;
01688 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_START, 0, 100);
01689 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, 100, 100);
01690 break;
01691 }
01692
01693
01694 rc = rpmpsmNext(psm, PSM_RPMIO_FLAGS);
01695
01696 if (rpmteFd(fi->te) == NULL) {
01697 rc = RPMRC_FAIL;
01698 break;
01699 }
01700
01701
01702 psm->cfd = Fdopen(fdDup(Fileno(rpmteFd(fi->te))), psm->rpmio_flags);
01703
01704 if (psm->cfd == NULL) {
01705 rc = RPMRC_FAIL;
01706 break;
01707 }
01708
01709 rc = fsmSetup(fi->fsm, FSM_PKGINSTALL, ts, fi,
01710 psm->cfd, NULL, &psm->failedFile);
01711 (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_UNCOMPRESS),
01712 fdstat_op(psm->cfd, FDSTAT_READ));
01713 (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
01714 fdstat_op(psm->cfd, FDSTAT_DIGEST));
01715 xx = fsmTeardown(fi->fsm);
01716
01717 saveerrno = errno;
01718 xx = Fclose(psm->cfd);
01719 psm->cfd = NULL;
01720
01721 errno = saveerrno;
01722
01723
01724 if (!rc)
01725 rc = rpmpsmNext(psm, PSM_COMMIT);
01726
01727
01728 psm->what = RPMCALLBACK_INST_PROGRESS;
01729 psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
01730 psm->total = psm->amount;
01731 xx = rpmpsmNext(psm, PSM_NOTIFY);
01732
01733 if (rc) {
01734 rpmError(RPMERR_CPIO,
01735 _("unpacking of archive failed%s%s: %s\n"),
01736 (psm->failedFile != NULL ? _(" on file ") : ""),
01737 (psm->failedFile != NULL ? psm->failedFile : ""),
01738 cpioStrerror(rc));
01739 rc = RPMRC_FAIL;
01740
01741
01742 psm->what = RPMCALLBACK_UNPACK_ERROR;
01743 psm->amount = 0;
01744 psm->total = 0;
01745 xx = rpmpsmNext(psm, PSM_NOTIFY);
01746
01747 break;
01748 }
01749 }
01750 if (psm->goal == PSM_PKGERASE) {
01751 int fc = rpmfiFC(fi);
01752
01753 if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
01754 if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY) break;
01755
01756
01757 if (rpmfiFC(fi) <= 0) {
01758 void * ptr;
01759 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_UNINST_START, 0, 100);
01760 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_UNINST_STOP, 0, 100);
01761 break;
01762 }
01763
01764 psm->what = RPMCALLBACK_UNINST_START;
01765 psm->amount = fc;
01766 psm->total = fc;
01767 xx = rpmpsmNext(psm, PSM_NOTIFY);
01768
01769 rc = fsmSetup(fi->fsm, FSM_PKGERASE, ts, fi,
01770 NULL, NULL, &psm->failedFile);
01771 xx = fsmTeardown(fi->fsm);
01772
01773 psm->what = RPMCALLBACK_UNINST_STOP;
01774 psm->amount = 0;
01775 psm->total = fc;
01776 xx = rpmpsmNext(psm, PSM_NOTIFY);
01777
01778 }
01779 if (psm->goal == PSM_PKGSAVE) {
01780 fileAction * actions = fi->actions;
01781 fileAction action = fi->action;
01782
01783 fi->action = FA_COPYOUT;
01784 fi->actions = NULL;
01785
01786 if (psm->fd == NULL) {
01787 rc = RPMRC_FAIL;
01788 break;
01789 }
01790
01791 xx = Fflush(psm->fd);
01792 psm->cfd = Fdopen(fdDup(Fileno(psm->fd)), psm->rpmio_flags);
01793
01794 if (psm->cfd == NULL) {
01795 rc = RPMRC_FAIL;
01796 break;
01797 }
01798
01799 rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, psm->cfd,
01800 NULL, &psm->failedFile);
01801 (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_COMPRESS),
01802 fdstat_op(psm->cfd, FDSTAT_WRITE));
01803 (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
01804 fdstat_op(psm->cfd, FDSTAT_DIGEST));
01805 xx = fsmTeardown(fi->fsm);
01806
01807 saveerrno = errno;
01808 xx = Fclose(psm->cfd);
01809 psm->cfd = NULL;
01810
01811 errno = saveerrno;
01812
01813
01814
01815 psm->what = RPMCALLBACK_INST_PROGRESS;
01816 psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
01817 psm->total = psm->amount;
01818 xx = rpmpsmNext(psm, PSM_NOTIFY);
01819
01820 fi->action = action;
01821 fi->actions = actions;
01822 }
01823 break;
01824 case PSM_POST:
01825 if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
01826
01827 if (psm->goal == PSM_PKGINSTALL) {
01828 int_32 installTime = (int_32) time(NULL);
01829 int fc = rpmfiFC(fi);
01830
01831 if (fi->h == NULL) break;
01832 if (fi->fstates != NULL && fc > 0)
01833 xx = headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE,
01834 fi->fstates, fc);
01835
01836 xx = headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
01837 &installTime, 1);
01838
01839 xx = headerAddEntry(fi->h, RPMTAG_INSTALLCOLOR, RPM_INT32_TYPE,
01840 &tscolor, 1);
01841
01842
01843
01844
01845
01846 if (fi->record && !(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY)) {
01847 rc = rpmpsmNext(psm, PSM_RPMDB_REMOVE);
01848 if (rc) break;
01849 }
01850
01851 rc = rpmpsmNext(psm, PSM_RPMDB_ADD);
01852 if (rc) break;
01853
01854 psm->scriptTag = RPMTAG_POSTIN;
01855 psm->progTag = RPMTAG_POSTINPROG;
01856 psm->sense = RPMSENSE_TRIGGERIN;
01857 psm->countCorrection = 0;
01858
01859 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOST)) {
01860 rc = rpmpsmNext(psm, PSM_SCRIPT);
01861 if (rc) break;
01862 }
01863 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERIN)) {
01864
01865 rc = rpmpsmNext(psm, PSM_TRIGGERS);
01866 if (rc) break;
01867
01868
01869 rc = rpmpsmNext(psm, PSM_IMMED_TRIGGERS);
01870 if (rc) break;
01871 }
01872
01873 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
01874 rc = markReplacedFiles(psm);
01875
01876 }
01877 if (psm->goal == PSM_PKGERASE) {
01878
01879 psm->scriptTag = RPMTAG_POSTUN;
01880 psm->progTag = RPMTAG_POSTUNPROG;
01881 psm->sense = RPMSENSE_TRIGGERPOSTUN;
01882 psm->countCorrection = -1;
01883
01884 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOSTUN)) {
01885 rc = rpmpsmNext(psm, PSM_SCRIPT);
01886 if (rc) break;
01887 }
01888
01889 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPOSTUN)) {
01890
01891 rc = rpmpsmNext(psm, PSM_TRIGGERS);
01892 if (rc) break;
01893 }
01894
01895 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
01896 rc = rpmpsmNext(psm, PSM_RPMDB_REMOVE);
01897 }
01898 if (psm->goal == PSM_PKGSAVE) {
01899 }
01900
01901
01902 xx = rpmpsmNext(psm, PSM_CHROOT_OUT);
01903 break;
01904 case PSM_UNDO:
01905 break;
01906 case PSM_FINI:
01907
01908 xx = rpmpsmNext(psm, PSM_CHROOT_OUT);
01909
01910 if (psm->fd != NULL) {
01911 saveerrno = errno;
01912 xx = Fclose(psm->fd);
01913 psm->fd = NULL;
01914
01915 errno = saveerrno;
01916
01917 }
01918
01919 if (psm->goal == PSM_PKGSAVE) {
01920 if (!rc && ts && ts->notify == NULL) {
01921 rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"),
01922 (psm->pkgURL ? psm->pkgURL : "???"));
01923 }
01924 }
01925
01926 if (rc) {
01927 if (psm->failedFile)
01928 rpmError(RPMERR_CPIO,
01929 _("%s failed on file %s: %s\n"),
01930 psm->stepName, psm->failedFile, cpioStrerror(rc));
01931 else
01932 rpmError(RPMERR_CPIO, _("%s failed: %s\n"),
01933 psm->stepName, cpioStrerror(rc));
01934
01935
01936 psm->what = RPMCALLBACK_CPIO_ERROR;
01937 psm->amount = 0;
01938 psm->total = 0;
01939
01940 xx = rpmpsmNext(psm, PSM_NOTIFY);
01941
01942 }
01943
01944
01945 if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
01946 if (psm->te != NULL)
01947 if (psm->te->h != NULL)
01948 psm->te->h = headerFree(psm->te->h);
01949 if (fi->h != NULL)
01950 fi->h = headerFree(fi->h);
01951 }
01952
01953 psm->oh = headerFree(psm->oh);
01954 psm->pkgURL = _free(psm->pkgURL);
01955 psm->rpmio_flags = _free(psm->rpmio_flags);
01956 psm->failedFile = _free(psm->failedFile);
01957
01958 fi->fgroup = hfd(fi->fgroup, -1);
01959 fi->fuser = hfd(fi->fuser, -1);
01960 fi->apath = _free(fi->apath);
01961 fi->fstates = _free(fi->fstates);
01962 break;
01963
01964 case PSM_PKGINSTALL:
01965 case PSM_PKGERASE:
01966 case PSM_PKGSAVE:
01967 psm->goal = stage;
01968 psm->rc = RPMRC_OK;
01969 psm->stepName = pkgStageString(stage);
01970
01971 rc = rpmpsmNext(psm, PSM_INIT);
01972 if (!rc) rc = rpmpsmNext(psm, PSM_PRE);
01973 if (!rc) rc = rpmpsmNext(psm, PSM_PROCESS);
01974 if (!rc) rc = rpmpsmNext(psm, PSM_POST);
01975 xx = rpmpsmNext(psm, PSM_FINI);
01976 break;
01977 case PSM_PKGCOMMIT:
01978 break;
01979
01980 case PSM_CREATE:
01981 break;
01982 case PSM_NOTIFY:
01983 { void * ptr;
01984
01985 ptr = rpmtsNotify(ts, psm->te, psm->what, psm->amount, psm->total);
01986
01987 } break;
01988 case PSM_DESTROY:
01989 break;
01990 case PSM_COMMIT:
01991 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_PKGCOMMIT)) break;
01992 if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY) break;
01993
01994 rc = fsmSetup(fi->fsm, FSM_PKGCOMMIT, ts, fi,
01995 NULL, NULL, &psm->failedFile);
01996 xx = fsmTeardown(fi->fsm);
01997 break;
01998
01999 case PSM_CHROOT_IN:
02000 { const char * rootDir = rpmtsRootDir(ts);
02001
02002 if (rootDir != NULL && !(rootDir[0] == '/' && rootDir[1] == '\0')
02003 && !rpmtsChrootDone(ts) && !psm->chrootDone)
02004 {
02005 static int _pw_loaded = 0;
02006 static int _gr_loaded = 0;
02007
02008 if (!_pw_loaded) {
02009 (void)getpwnam("root");
02010 endpwent();
02011 _pw_loaded++;
02012 }
02013 if (!_gr_loaded) {
02014 (void)getgrnam("root");
02015 endgrent();
02016 _gr_loaded++;
02017 }
02018
02019 xx = chdir("/");
02020
02021 if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
02022 rc = chroot(rootDir);
02023
02024 psm->chrootDone = 1;
02025 (void) rpmtsSetChrootDone(ts, 1);
02026 }
02027 } break;
02028 case PSM_CHROOT_OUT:
02029
02030 if (psm->chrootDone) {
02031 const char * rootDir = rpmtsRootDir(ts);
02032 const char * currDir = rpmtsCurrDir(ts);
02033
02034 if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
02035 rc = chroot(".");
02036
02037 psm->chrootDone = 0;
02038 (void) rpmtsSetChrootDone(ts, 0);
02039 if (currDir != NULL)
02040 xx = chdir(currDir);
02041 }
02042 break;
02043 case PSM_SCRIPT:
02044 rc = runInstScript(psm);
02045 break;
02046 case PSM_TRIGGERS:
02047
02048 rc = runTriggers(psm);
02049 break;
02050 case PSM_IMMED_TRIGGERS:
02051
02052 rc = runImmedTriggers(psm);
02053 break;
02054
02055 case PSM_RPMIO_FLAGS:
02056 { const char * payload_compressor = NULL;
02057 char * t;
02058
02059
02060 if (!hge(fi->h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
02061 (void **) &payload_compressor, NULL))
02062 payload_compressor = "gzip";
02063
02064 psm->rpmio_flags = t = xmalloc(sizeof("w9.gzdio"));
02065 *t = '\0';
02066 t = stpcpy(t, ((psm->goal == PSM_PKGSAVE) ? "w9" : "r"));
02067 if (!strcmp(payload_compressor, "gzip"))
02068 t = stpcpy(t, ".gzdio");
02069 if (!strcmp(payload_compressor, "bzip2"))
02070 t = stpcpy(t, ".bzdio");
02071 rc = RPMRC_OK;
02072 } break;
02073
02074 case PSM_RPMDB_LOAD:
02075 assert(psm->mi == NULL);
02076 psm->mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
02077 &fi->record, sizeof(fi->record));
02078
02079 fi->h = rpmdbNextIterator(psm->mi);
02080 if (fi->h != NULL)
02081 fi->h = headerLink(fi->h);
02082
02083 psm->mi = rpmdbFreeIterator(psm->mi);
02084 rc = (fi->h != NULL ? RPMRC_OK : RPMRC_FAIL);
02085 break;
02086 case PSM_RPMDB_ADD:
02087 if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
02088 if (fi->h == NULL) break;
02089 (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
02090 if (!(rpmtsVSFlags(ts) & RPMVSF_NOHDRCHK))
02091 rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
02092 ts, headerCheck);
02093 else
02094 rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
02095 NULL, NULL);
02096
02097
02098
02099
02100 rpmteSetDBInstance(psm->te, myinstall_instance);
02101
02102
02103
02104
02105
02106 if (rpmtsGetScore(ts) != NULL &&
02107 rpmtsGetType(ts) != RPMTRANS_TYPE_ROLLBACK &&
02108 rpmtsGetType(ts) != RPMTRANS_TYPE_AUTOROLLBACK)
02109 {
02110
02111
02112
02113 rpmtsScore score = rpmtsGetScore(ts);
02114 if (score != NULL) {
02115 rpmtsScoreEntry se;
02116
02117
02118
02119 rpmMessage(RPMMESS_DEBUG,
02120 _("Attempting to mark %s as installed in score board(%u).\n"),
02121 rpmteN(psm->te), (unsigned) score);
02122 se = rpmtsScoreGetEntry(score, rpmteN(psm->te));
02123 if (se != NULL) se->installed = 1;
02124 }
02125 }
02126 (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
02127 break;
02128 case PSM_RPMDB_REMOVE:
02129 if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
02130 (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
02131 rc = rpmdbRemove(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->record,
02132 NULL, NULL);
02133
02134
02135
02136
02137
02138 if (rpmtsGetScore(ts) != NULL &&
02139 rpmtsGetType(ts) != RPMTRANS_TYPE_ROLLBACK &&
02140 rpmtsGetType(ts) != RPMTRANS_TYPE_AUTOROLLBACK)
02141 {
02142
02143
02144
02145 rpmtsScore score = rpmtsGetScore(ts);
02146
02147 if (score != NULL) {
02148 rpmtsScoreEntry se;
02149
02150
02151
02152 rpmMessage(RPMMESS_DEBUG,
02153 _("Attempting to mark %s as erased in score board(0x%x).\n"),
02154 rpmteN(psm->te), (unsigned) score);
02155 se = rpmtsScoreGetEntry(score, rpmteN(psm->te));
02156 if (se != NULL) se->erased = 1;
02157 }
02158 }
02159
02160 (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
02161 break;
02162
02163 default:
02164 break;
02165 }
02166
02167
02168
02169 return rc;
02170
02171 }
02172