1996-06-08 02:32:10 +08:00
|
|
|
/* reqprov.c -- require/provide handling */
|
|
|
|
|
1998-03-05 00:51:06 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1996-06-08 02:32:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "spec.h"
|
1996-06-08 02:32:10 +08:00
|
|
|
#include "reqprov.h"
|
|
|
|
#include "messages.h"
|
|
|
|
#include "rpmlib.h"
|
1996-06-28 02:25:09 +08:00
|
|
|
#include "misc.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "lib/misc.h"
|
1996-06-08 02:32:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int addReqProv(Spec spec, Package pkg, int flag, char *name, char *version)
|
1996-06-08 02:32:10 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
char **names;
|
|
|
|
char **versions = NULL;
|
|
|
|
int *flags = NULL;
|
|
|
|
int nametag = 0;
|
|
|
|
int versiontag = 0;
|
|
|
|
int flagtag = 0;
|
|
|
|
int len;
|
|
|
|
int extra = 0;
|
1996-06-08 02:32:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (flag & RPMSENSE_PROVIDES) {
|
|
|
|
nametag = RPMTAG_PROVIDES;
|
|
|
|
} else if (flag & RPMSENSE_OBSOLETES) {
|
|
|
|
nametag = RPMTAG_OBSOLETES;
|
|
|
|
} else if (flag & RPMSENSE_CONFLICTS) {
|
|
|
|
nametag = RPMTAG_CONFLICTNAME;
|
|
|
|
versiontag = RPMTAG_CONFLICTVERSION;
|
|
|
|
flagtag = RPMTAG_CONFLICTFLAGS;
|
|
|
|
} else if (flag & RPMSENSE_PREREQ) {
|
|
|
|
nametag = RPMTAG_REQUIRENAME;
|
|
|
|
versiontag = RPMTAG_REQUIREVERSION;
|
|
|
|
flagtag = RPMTAG_REQUIREFLAGS;
|
|
|
|
extra = RPMSENSE_PREREQ;
|
1997-06-20 03:46:19 +08:00
|
|
|
} else {
|
1998-01-13 05:31:29 +08:00
|
|
|
nametag = RPMTAG_REQUIRENAME;
|
|
|
|
versiontag = RPMTAG_REQUIREVERSION;
|
|
|
|
flagtag = RPMTAG_REQUIREFLAGS;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
flag = (flag & RPMSENSE_SENSEMASK) | extra;
|
|
|
|
if (!version) {
|
|
|
|
version = "";
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (headerGetEntry(pkg->header, nametag, NULL, (void *) &names, &len)) {
|
|
|
|
if (flagtag) {
|
|
|
|
headerGetEntry(pkg->header, versiontag, NULL,
|
|
|
|
(void *) &versions, NULL);
|
|
|
|
headerGetEntry(pkg->header, flagtag, NULL, (void *) &flags, NULL);
|
1996-08-15 05:02:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
while (len) {
|
|
|
|
len--;
|
|
|
|
if (!strcmp(names[len], name)) {
|
|
|
|
if (!flagtag ||
|
|
|
|
(!strcmp(versions[len], version) && flags[len] == flag)) {
|
|
|
|
/* The same */
|
|
|
|
FREE(names);
|
|
|
|
FREE(versions);
|
|
|
|
return 0;
|
1996-08-15 05:02:54 +08:00
|
|
|
}
|
1996-07-21 07:00:33 +08:00
|
|
|
}
|
1996-08-15 05:02:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(names);
|
|
|
|
FREE(versions);
|
1996-08-15 05:02:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
headerAddOrAppendEntry(pkg->header, nametag,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &name, 1);
|
|
|
|
if (flagtag) {
|
|
|
|
headerAddOrAppendEntry(pkg->header, versiontag,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &version, 1);
|
|
|
|
headerAddOrAppendEntry(pkg->header, flagtag,
|
|
|
|
RPM_INT32_TYPE, &flag, 1);
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1996-08-15 05:02:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
return 0;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int generateAutoReqProv(Spec spec, Package pkg,
|
|
|
|
struct cpioFileMapping *cpioList, int cpioCount)
|
1996-06-08 02:32:10 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
StringBuf writeBuf;
|
1996-08-15 05:02:54 +08:00
|
|
|
int writeBytes;
|
1998-01-13 05:31:29 +08:00
|
|
|
StringBuf readBuf;
|
|
|
|
char *argv[2];
|
|
|
|
char **f, **fsave;
|
1996-06-08 02:32:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (!cpioCount) {
|
1996-08-15 05:02:54 +08:00
|
|
|
return 0;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
writeBuf = newStringBuf();
|
1996-08-15 05:02:54 +08:00
|
|
|
writeBytes = 0;
|
1998-01-13 05:31:29 +08:00
|
|
|
while (cpioCount--) {
|
|
|
|
writeBytes += strlen(cpioList->fsPath) + 1;
|
|
|
|
appendLineStringBuf(writeBuf, cpioList->fsPath);
|
|
|
|
cpioList++;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1996-08-15 05:02:54 +08:00
|
|
|
|
|
|
|
/*** Do Provides ***/
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "Finding provides...\n");
|
1996-08-15 05:02:54 +08:00
|
|
|
|
|
|
|
argv[0] = "find-provides";
|
|
|
|
argv[1] = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
readBuf = getOutputFrom(NULL, argv,
|
|
|
|
getStringBuf(writeBuf), writeBytes, 1);
|
|
|
|
if (!readBuf) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_EXEC, "Failed to find provides");
|
1998-01-13 05:31:29 +08:00
|
|
|
freeStringBuf(writeBuf);
|
|
|
|
return RPMERR_EXEC;
|
1996-08-15 05:02:54 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
f = fsave = splitString(getStringBuf(readBuf),
|
|
|
|
strlen(getStringBuf(readBuf)), '\n');
|
|
|
|
freeStringBuf(readBuf);
|
1996-08-15 05:02:54 +08:00
|
|
|
while (*f) {
|
|
|
|
if (**f) {
|
1998-01-13 05:31:29 +08:00
|
|
|
addReqProv(spec, pkg, RPMSENSE_PROVIDES, *f, NULL);
|
1996-08-15 05:02:54 +08:00
|
|
|
}
|
|
|
|
f++;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(fsave);
|
1996-08-15 05:02:54 +08:00
|
|
|
|
|
|
|
/*** Do Requires ***/
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, "Finding requires...\n");
|
|
|
|
|
1996-11-22 06:24:34 +08:00
|
|
|
argv[0] = "find-requires";
|
|
|
|
argv[1] = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
readBuf = getOutputFrom(NULL, argv,
|
|
|
|
getStringBuf(writeBuf), writeBytes, 0);
|
|
|
|
if (!readBuf) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_EXEC, "Failed to find requires");
|
1998-01-13 05:31:29 +08:00
|
|
|
freeStringBuf(writeBuf);
|
|
|
|
return RPMERR_EXEC;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
f = fsave = splitString(getStringBuf(readBuf),
|
|
|
|
strlen(getStringBuf(readBuf)), '\n');
|
|
|
|
freeStringBuf(readBuf);
|
1996-06-28 02:25:09 +08:00
|
|
|
while (*f) {
|
1996-11-22 06:24:34 +08:00
|
|
|
if (**f) {
|
1998-01-13 05:31:29 +08:00
|
|
|
addReqProv(spec, pkg, RPMSENSE_ANY, *f, NULL);
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1996-06-28 02:25:09 +08:00
|
|
|
f++;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(fsave);
|
1996-08-15 05:02:54 +08:00
|
|
|
|
|
|
|
/*** Clean Up ***/
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
freeStringBuf(writeBuf);
|
1996-08-15 05:02:54 +08:00
|
|
|
|
1996-06-08 02:32:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
void printReqs(Spec spec, Package pkg)
|
1996-06-08 02:32:10 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
int startedPreReq = 0;
|
|
|
|
int startedReq = 0;
|
|
|
|
|
|
|
|
char **names;
|
|
|
|
int x, count;
|
|
|
|
int *flags;
|
|
|
|
|
|
|
|
if (headerGetEntry(pkg->header, RPMTAG_PROVIDES,
|
|
|
|
NULL, (void **) &names, &count)) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "Provides:");
|
|
|
|
x = 0;
|
|
|
|
while (x < count) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, " %s", names[x]);
|
|
|
|
x++;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, "\n");
|
|
|
|
FREE(names);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (headerGetEntry(pkg->header, RPMTAG_REQUIRENAME,
|
|
|
|
NULL, (void **) &names, &count)) {
|
|
|
|
headerGetEntry(pkg->header, RPMTAG_REQUIREFLAGS,
|
|
|
|
NULL, (void **) &flags, NULL);
|
|
|
|
x = 0;
|
|
|
|
while (x < count) {
|
|
|
|
if (flags[x] & RPMSENSE_PREREQ) {
|
|
|
|
if (! startedPreReq) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "Prereqs:");
|
|
|
|
startedPreReq = 1;
|
|
|
|
}
|
|
|
|
rpmMessage(RPMMESS_NORMAL, " %s", names[x]);
|
1996-06-28 04:16:20 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
x++;
|
1996-06-28 04:16:20 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, "\n");
|
|
|
|
x = 0;
|
|
|
|
while (x < count) {
|
|
|
|
if (! (flags[x] & RPMSENSE_PREREQ)) {
|
|
|
|
if (! startedReq) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "Requires:");
|
|
|
|
startedReq = 1;
|
1997-06-20 03:46:19 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, " %s", names[x]);
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
x++;
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, "\n");
|
|
|
|
FREE(names);
|
1996-06-08 02:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|