Eliminate setFileOwners() and installSources().

Resurrect source installs.

CVS patchset: 4606
CVS date: 2001/03/04 17:15:56
This commit is contained in:
jbj 2001-03-04 17:15:56 +00:00
parent a77bec0d7e
commit 2ad94143e2
2 changed files with 182 additions and 204 deletions

326
lib/psm.c
View File

@ -30,6 +30,42 @@ static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) {
return NULL;
}
int rpmVersionCompare(Header first, Header second)
{
const char * one, * two;
int_32 * epochOne, * epochTwo;
int rc;
if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
epochOne = NULL;
if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo,
NULL))
epochTwo = NULL;
if (epochOne && !epochTwo)
return 1;
else if (!epochOne && epochTwo)
return -1;
else if (epochOne && epochTwo) {
if (*epochOne < *epochTwo)
return -1;
else if (*epochOne > *epochTwo)
return 1;
}
headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
rc = rpmvercmp(one, two);
if (rc)
return rc;
headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
return rpmvercmp(one, two);
}
void loadFi(Header h, TFI_t fi)
{
HGE_t hge;
@ -241,39 +277,6 @@ static int rpmInstallLoadMacros(TFI_t fi, Header h)
return 0;
}
/**
* Localize user/group id's.
* @param fi transaction element file info
* @return 0 always
*/
static int setFileOwners(TFI_t fi)
{
uid_t uid;
gid_t gid;
int i;
for (i = 0; i < fi->fc; i++) {
if (unameToUid(fi->fuser[i], &uid)) {
rpmMessage(RPMMESS_WARNING,
_("user %s does not exist - using root\n"), fi->fuser[i]);
uid = 0;
/* XXX this diddles header memory. */
fi->fmodes[i] &= ~S_ISUID; /* turn off the suid bit */
}
if (gnameToGid(fi->fgroup[i], &gid)) {
rpmMessage(RPMMESS_WARNING,
_("group %s does not exist - using root\n"), fi->fgroup[i]);
gid = 0;
/* XXX this diddles header memory. */
fi->fmodes[i] &= ~S_ISGID; /* turn off the sgid bit */
}
fi->fuids[i] = uid;
fi->fgids[i] = gid;
}
return 0;
}
/**
* Copy file data from h to newH.
* @param h header from
@ -566,36 +569,86 @@ static rpmRC chkdir (const char * dpath, const char * dname)
return RPMRC_OK;
}
/**
* @param ts transaction set
* @param fi transaction element file info
* @retval specFilePtr address of spec file name
* @return rpmRC return code
*/
static rpmRC installSources(const rpmTransactionSet ts, TFI_t fi,
/*@out@*/ const char ** specFilePtr)
rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd,
const char ** specFilePtr,
rpmCallbackFunction notify, rpmCallbackData notifyData,
char ** cookie)
{
HFD_t hfd = fi->hfd;
const char * _sourcedir = rpmGenPath(ts->rootDir, "%{_sourcedir}", "");
const char * _specdir = rpmGenPath(ts->rootDir, "%{_specdir}", "");
rpmdb rpmdb = NULL;
rpmTransactionSet ts = rpmtransCreateSet(rpmdb, rootDir);
TFI_t fi = xcalloc(sizeof(*fi), 1);
const char * _sourcedir = NULL;
const char * _specdir = NULL;
const char * specFile = NULL;
rpmRC rc = RPMRC_OK;
HGE_t hge;
HFD_t hfd;
Header h;
struct psm_s psmbuf;
PSM_t psm = &psmbuf;
int isSource;
rpmRC rc;
int i;
rpmMessage(RPMMESS_DEBUG, _("installing a source package\n"));
ts->notify = notify;
ts->notifyData = notifyData;
rc = chkdir(_sourcedir, "sourcedir");
if (rc) {
rc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
if (rc)
goto exit;
if (!isSource) {
rpmError(RPMERR_NOTSRPM, _("source package expected, binary found\n"));
rc = RPMRC_FAIL;
goto exit;
}
rc = chkdir(_specdir, "specdir");
if (rc) {
rc = RPMRC_FAIL;
goto exit;
(void) rpmtransAddPackage(ts, h, fd, NULL, 0, NULL);
fi->type = TR_ADDED;
fi->ap = ts->addedPackages.list;
loadFi(h, fi);
hge = fi->hge;
hfd = fi->hfd;
headerFree(h); /* XXX reference held by transaction set */
h = NULL;
rpmInstallLoadMacros(fi, fi->h);
memset(psm, 0, sizeof(*psm));
psm->ts = ts;
psm->fi = fi;
if (cookie) {
*cookie = NULL;
if (hge(h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL))
*cookie = xstrdup(*cookie);
}
/* XXX FIXME: can't do endian neutral MD5 verification yet. */
fi->fmd5s = hfd(fi->fmd5s, -1);
/* XXX FIXME: don't do per-file mapping, force global flags. */
fi->fmapflags = hfd(fi->fmapflags, -1);
fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
fi->uid = getuid();
fi->gid = getgid();
fi->astriplen = 0;
fi->striplen = 0;
fi->fuids = xcalloc(sizeof(*fi->fuids), fi->fc);
fi->fgids = xcalloc(sizeof(*fi->fgids), fi->fc);
for (i = 0; i < fi->fc; i++) {
fi->fuids[i] = fi->uid;
fi->fgids[i] = fi->gid;
}
for (i = 0; i < fi->fc; i++) {
fi->actions[i] = FA_CREATE;
}
rpmBuildFileList(fi->h, &fi->apath, NULL);
i = fi->fc;
if (headerIsEntry(fi->h, RPMTAG_COOKIE))
for (i = 0; i < fi->fc; i++)
@ -610,6 +663,20 @@ static rpmRC installSources(const rpmTransactionSet ts, TFI_t fi,
}
}
_sourcedir = rpmGenPath(ts->rootDir, "%{_sourcedir}", "");
rc = chkdir(_sourcedir, "sourcedir");
if (rc) {
rc = RPMRC_FAIL;
goto exit;
}
_specdir = rpmGenPath(ts->rootDir, "%{_specdir}", "");
rc = chkdir(_specdir, "specdir");
if (rc) {
rc = RPMRC_FAIL;
goto exit;
}
/* Build dnl/dil with {_sourcedir, _specdir} as values. */
if (i < fi->fc) {
int speclen = strlen(_specdir) + 2;
@ -637,144 +704,33 @@ static rpmRC installSources(const rpmTransactionSet ts, TFI_t fi,
goto exit;
}
{ struct psm_s psmbuf;
PSM_t psm = &psmbuf;
memset(psm, 0, sizeof(*psm));
psm->ts = ts;
psm->fi = fi;
psm->goal = PSM_PKGINSTALL;
rc = psmStage(psm, PSM_PROCESS);
rc = psmStage(psm, PSM_PROCESS);
(void) psmStage(psm, PSM_FINI);
}
(void) psmStage(psm, PSM_FINI);
if (rc) {
rc = RPMRC_FAIL;
goto exit;
}
if (rc) rc = RPMRC_FAIL;
exit:
if (rc == RPMRC_OK && specFile && specFilePtr)
*specFilePtr = specFile;
else
specFile = _free(specFile);
_specdir = _free(_specdir);
_sourcedir = _free(_sourcedir);
return rc;
}
int rpmVersionCompare(Header first, Header second)
{
const char * one, * two;
int_32 * epochOne, * epochTwo;
int rc;
if (h)
headerFree(h);
if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
epochOne = NULL;
if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo,
NULL))
epochTwo = NULL;
if (epochOne && !epochTwo)
return 1;
else if (!epochOne && epochTwo)
return -1;
else if (epochOne && epochTwo) {
if (*epochOne < *epochTwo)
return -1;
else if (*epochOne > *epochTwo)
return 1;
}
headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
rc = rpmvercmp(one, two);
if (rc)
return rc;
headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
return rpmvercmp(one, two);
}
rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd,
const char ** specFile,
rpmCallbackFunction notify, rpmCallbackData notifyData,
char ** cookie)
{
rpmdb rpmdb = NULL;
rpmTransactionSet ts = rpmtransCreateSet(rpmdb, rootDir);
TFI_t fi = xcalloc(sizeof(*fi), 1);
int isSource;
Header h;
int major, minor;
rpmRC rc;
int i;
ts->notify = notify;
ts->notifyData = notifyData;
rc = rpmReadPackageHeader(fd, &h, &isSource, &major, &minor);
if (rc)
goto exit;
if (!isSource) {
rpmError(RPMERR_NOTSRPM, _("source package expected, binary found\n"));
rc = RPMRC_FAIL;
goto exit;
}
if (cookie) {
*cookie = NULL;
if (headerGetEntry(h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL))
*cookie = xstrdup(*cookie);
}
(void) rpmtransAddPackage(ts, h, fd, NULL, 0, NULL);
fi->type = TR_ADDED;
fi->ap = ts->addedPackages.list;
loadFi(h, fi);
headerFree(h); /* XXX reference held by transaction set */
if (fi->fmd5s) { /* DYING */
free((void **)fi->fmd5s); fi->fmd5s = NULL;
}
if (fi->fmapflags) { /* DYING */
free((void **)fi->fmapflags); fi->fmapflags = NULL;
}
fi->uid = getuid();
fi->gid = getgid();
fi->astriplen = 0;
fi->striplen = 0;
fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
fi->fuids = xcalloc(sizeof(*fi->fuids), fi->fc);
fi->fgids = xcalloc(sizeof(*fi->fgids), fi->fc);
for (i = 0; i < fi->fc; i++) {
fi->fuids[i] = fi->uid;
fi->fgids[i] = fi->gid;
}
for (i = 0; i < fi->fc; i++) {
fi->actions[i] = FA_CREATE;
}
rpmBuildFileList(fi->h, &fi->apath, NULL);
rpmInstallLoadMacros(fi, fi->h);
rc = installSources(ts, fi, specFile);
exit:
if (fi) {
freeFi(fi);
free(fi);
}
if (ts)
rpmtransFree(ts);
return rc;
}
@ -1508,11 +1464,37 @@ assert(psm->mi == NULL);
if (psm->goal == PSM_PKGINSTALL) {
struct availablePackage * alp = fi->ap;
int i;
if (fi->fc <= 0) break;
if (ts->transFlags & RPMTRANS_FLAG_JUSTDB) break;
rc = setFileOwners(fi);
for (i = 0; i < fi->fc; i++) {
uid_t uid;
gid_t gid;
uid = fi->uid;
gid = fi->gid;
if (fi->fuser && unameToUid(fi->fuser[i], &uid)) {
rpmMessage(RPMMESS_WARNING,
_("user %s does not exist - using root\n"),
fi->fuser[i]);
uid = 0;
/* XXX this diddles header memory. */
fi->fmodes[i] &= ~S_ISUID; /* turn off the suid bit */
}
if (fi->fgroup && gnameToGid(fi->fgroup[i], &gid)) {
rpmMessage(RPMMESS_WARNING,
_("group %s does not exist - using root\n"),
fi->fgroup[i]);
gid = 0;
/* XXX this diddles header memory. */
fi->fmodes[i] &= ~S_ISGID; /* turn off the sgid bit */
}
if (fi->fuids) fi->fuids[i] = uid;
if (fi->fgids) fi->fgids[i] = gid;
}
/* Retrieve type of payload compression. */
rc = psmStage(psm, PSM_RPMIO_FLAGS);

View File

@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2001-03-04 10:09-0500\n"
"POT-Creation-Date: 2001-03-04 12:14-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1853,7 +1853,7 @@ msgstr ""
msgid "Could not open %s: %s\n"
msgstr ""
#: build/pack.c:484 lib/psm.c:1487
#: build/pack.c:484 lib/psm.c:1443
#, c-format
msgid "Unable to write package: %s\n"
msgstr ""
@ -1883,7 +1883,7 @@ msgstr ""
msgid "Unable to write payload to %s: %s\n"
msgstr ""
#: build/pack.c:566 lib/psm.c:1697
#: build/pack.c:566 lib/psm.c:1679
#, c-format
msgid "Wrote: %s\n"
msgstr ""
@ -2556,7 +2556,7 @@ msgstr ""
msgid "dataLength() RPM_STRING_TYPE count must be 1.\n"
msgstr ""
#: lib/header.c:207 lib/header.c:1081 lib/psm.c:370
#: lib/header.c:207 lib/header.c:1081 lib/psm.c:373
#, c-format
msgid "Data type %d not supported\n"
msgstr ""
@ -2924,68 +2924,64 @@ msgstr ""
msgid "unknown error %d encountered while manipulating package %s"
msgstr ""
#: lib/psm.c:258
#, c-format
msgid "user %s does not exist - using root\n"
msgstr ""
#: lib/psm.c:266
#, c-format
msgid "group %s does not exist - using root\n"
msgstr ""
#: lib/psm.c:557
#: lib/psm.c:560
#, c-format
msgid "cannot create %s %s\n"
msgstr ""
#: lib/psm.c:563
#: lib/psm.c:566
#, c-format
msgid "cannot write to %s\n"
msgstr ""
#: lib/psm.c:585
msgid "installing a source package\n"
msgstr ""
#: lib/psm.c:635
msgid "source package contains no .spec file\n"
msgstr ""
#: lib/psm.c:724
#: lib/psm.c:600
msgid "source package expected, binary found\n"
msgstr ""
#: lib/psm.c:994
#: lib/psm.c:702
msgid "source package contains no .spec file\n"
msgstr ""
#: lib/psm.c:950
#, c-format
msgid "execution of %s scriptlet from %s-%s-%s failed, waitpid returned %s\n"
msgstr ""
#: lib/psm.c:1001
#: lib/psm.c:957
#, c-format
msgid "execution of %s scriptlet from %s-%s-%s failed, exit status %d\n"
msgstr ""
#: lib/psm.c:1305
#: lib/psm.c:1261
#, c-format
msgid "%s: %s-%s-%s has %d files, test = %d\n"
msgstr ""
#: lib/psm.c:1418
#: lib/psm.c:1374
#, c-format
msgid "%s: %s scriptlet failed (%d), skipping %s-%s-%s\n"
msgstr ""
#: lib/psm.c:1536
#: lib/psm.c:1480
#, c-format
msgid "user %s does not exist - using root\n"
msgstr ""
#: lib/psm.c:1489
#, c-format
msgid "group %s does not exist - using root\n"
msgstr ""
#: lib/psm.c:1518
#, c-format
msgid "unpacking of archive failed%s%s: %s\n"
msgstr ""
#: lib/psm.c:1537
#: lib/psm.c:1519
msgid " on file "
msgstr ""
#: lib/psm.c:1788
#: lib/psm.c:1770
#, c-format
msgid "%s: running %s script(s) (if any)\n"
msgstr ""