Backport packaging '%pretrans' Lua scriptlets

Based on rpm-4.4 with minor changes.
Running functionality is not backported.

Based-on: 73260d956c ("Implemented %pretrans and %posttrans script slots.")
Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
This commit is contained in:
2022-10-11 03:24:36 +03:00
parent 9cabb6dd24
commit 36d9f39b47
7 changed files with 45 additions and 1 deletions

View File

@ -232,6 +232,13 @@ static int processScriptFiles(Spec spec, Package pkg)
return RPMERR_BADFILENAME;
}
}
if (pkg->preTransFile) {
if (addFileToTag(spec, pkg->preTransFile, pkg->header, RPMTAG_PRETRANS)) {
rpmError(RPMERR_BADFILENAME,
_("Could not open preTrans file: %s\n"), pkg->preTransFile);
return RPMERR_BADFILENAME;
}
}
if (pkg->verifyFile) {
if (addFileToTag(spec, pkg->verifyFile, pkg->header,
RPMTAG_VERIFYSCRIPT)) {

View File

@ -128,6 +128,12 @@ int parseScript(Spec spec, int parsePart)
progtag = RPMTAG_POSTUNPROG;
partname = "%postun";
break;
case PART_PRETRANS:
tag = RPMTAG_PRETRANS;
tagflags = 0;
progtag = RPMTAG_PRETRANSPROG;
partname = "%pretrans";
break;
case PART_VERIFYSCRIPT:
tag = RPMTAG_VERIFYSCRIPT;
tagflags = RPMSENSE_SCRIPT_VERIFY;
@ -181,6 +187,14 @@ int parseScript(Spec spec, int parsePart)
while ((arg = poptGetNextOpt(optCon)) > 0) {
switch (arg) {
case 'p':
if (prog[0] == '<') {
if (prog[strlen(prog)-1] != '>') {
rpmlog(RPMLOG_ERR,
_("line %d: internal script must end "
"with \'>\': %s\n"), spec->lineNum, prog);
goto exit;
}
} else
if (prog[0] != '/') {
rpmError(RPMERR_BADSPEC,
_("line %d: script program must begin "
@ -188,6 +202,7 @@ int parseScript(Spec spec, int parsePart)
rc = RPMERR_BADSPEC;
goto exit;
}
/*@switchbreak@*/ break;
case 'n':
flag = PART_NAME;
@ -260,6 +275,16 @@ int parseScript(Spec spec, int parsePart)
stripTrailingBlanksStringBuf(sb);
p = getStringBuf(sb);
if (!strcmp(progArgv[0], "<lua>")) {
(void) rpmlibNeedsFeature(pkg->header,
"BuiltinLuaScripts", "4.2.2-1");
} else if (progArgv[0][0] == '<') {
rpmError(RPMERR_BADSPEC,
_("line %d: unsupported internal script: %s\n"),
spec->lineNum, progArgv[0]);
rc = RPMERR_BADSPEC;
goto exit;
} else
if (pkg->autoReq && *pkg->autoReq)
(void) addReqProv(spec, pkg->header, (tagflags | RPMSENSE_INTERP), progArgv[0], NULL, 0);
@ -300,6 +325,9 @@ int parseScript(Spec spec, int parsePart)
case PART_POSTUN:
pkg->postUnFile = xstrdup(file);
break;
case PART_PRETRANS:
pkg->preTransFile = xstrdup(file);
break;
case PART_VERIFYSCRIPT:
pkg->verifyFile = xstrdup(file);
break;

View File

@ -32,6 +32,7 @@ static struct PartRec {
{ PART_CLEAN, 0, "%clean"},
{ PART_PREUN, 0, "%preun"},
{ PART_POSTUN, 0, "%postun"},
{ PART_PRETRANS, 0, "%pretrans"},
{ PART_PRE, 0, "%pre"},
{ PART_POST, 0, "%post"},
{ PART_FILES, 0, "%files"},
@ -482,6 +483,7 @@ static tags_struct tags_common_list[] = {
{0, "package"},
{0, "post"},
{0, "postun"},
{0, "pretrans"},
{0, "pre"},
{0, "prep"},
{0, "preun"},
@ -736,6 +738,7 @@ fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootU
case PART_POST:
case PART_PREUN:
case PART_POSTUN:
case PART_PRETRANS:
case PART_VERIFYSCRIPT:
case PART_TRIGGERIN:
case PART_TRIGGERUN:

View File

@ -71,7 +71,8 @@ typedef enum rpmParseState_e {
PART_VERIFYSCRIPT = 16, /*!< */
PART_BUILDARCHITECTURES= 17,/*!< */
PART_TRIGGERPOSTUN = 18, /*!< */
PART_LAST = 19 /*!< */
PART_PRETRANS = 19, /*!< */
PART_LAST = 20 /*!< */
} rpmParseState;
#define STRIP_NOTHING 0

View File

@ -168,6 +168,7 @@ struct PackageStruct {
/*@only@*/ const char * postInFile; /*!< %post scriptlet. */
/*@only@*/ const char * preUnFile; /*!< %preun scriptlet. */
/*@only@*/ const char * postUnFile; /*!< %postun scriptlet. */
/*@only@*/ const char * preTransFile; /*!< %pretrans scriptlet. */
/*@only@*/ const char * verifyFile; /*!< %verifyscript scriptlet. */
/*@only@*/ StringBuf specialDoc;

View File

@ -129,6 +129,7 @@ Package newPackage(Spec spec)
p->postInFile = NULL;
p->preUnFile = NULL;
p->postUnFile = NULL;
p->preTransFile = NULL;
p->verifyFile = NULL;
p->specialDoc = NULL;
@ -157,6 +158,7 @@ Package freePackage(Package pkg)
pkg->postInFile = _free(pkg->postInFile);
pkg->preUnFile = _free(pkg->preUnFile);
pkg->postUnFile = _free(pkg->postUnFile);
pkg->preTransFile = _free(pkg->preTransFile);
pkg->verifyFile = _free(pkg->verifyFile);
pkg->header = headerFree(pkg->header);

View File

@ -442,6 +442,8 @@ typedef enum rpmTag_e {
RPMTAG_FILEDEPENDSN = 1144,
RPMTAG_DEPENDSDICT = 1145,
RPMTAG_SOURCEPKGID = 1146,
RPMTAG_PRETRANS = 1151, /* s */
RPMTAG_PRETRANSPROG = 1153, /* s[] */
RPMTAG_DISTTAG = 1155, /* s */
RPMTAG_VCS = 5034, /* s */
RPMTAG_AUTOINSTALLED = 5094, /* i */