arg1 += psm->countCorrection;
if (triggersAlreadyRun == NULL || triggersAlreadyRun[ix] == 0) {
- /* XXX TODO add rpmScript API to handle this, ugh */
- char *macro = NULL;
- char *qformat = NULL;
- char *args[2] = { triggerProgs[ix], NULL };
- struct rpmScript_s script = {
- .tag = triggertag(psm->sense),
- .body = triggerScripts[ix],
- .flags = triggerFlags ? triggerFlags[ix] : 0,
- .args = args
- };
-
- if (script.body && (script.flags & RPMSCRIPT_EXPAND)) {
- macro = rpmExpand(script.body, NULL);
- script.body = macro;
- }
- if (script.body && (script.flags & RPMSCRIPT_QFORMAT)) {
- qformat = headerFormat(trigH, script.body, NULL);
- script.body = qformat;
- }
-
- rc = runScript(psm, pfx.data, &script, arg1, arg2);
+ rpmScript script;
+
+ script = rpmScriptNew(trigH, triggertag(psm->sense),
+ triggerScripts[ix],
+ triggerFlags ? triggerFlags[ix] : 0);
+
+ script->args = xcalloc(2, sizeof(*script->args));
+ script->args[0] = triggerProgs[ix];
+ script->args[1] = NULL;
+
+ rc = runScript(psm, pfx.data, script, arg1, arg2);
if (triggersAlreadyRun != NULL)
triggersAlreadyRun[ix] = 1;
- free(macro);
- free(qformat);
+
+ rpmScriptFree(script);
}
}
}
return "%unknownscript";
}
+rpmScript rpmScriptNew(Header h, rpmTagVal tag, const char *body,
+ rpmscriptFlags flags)
+{
+ char *nevra = headerGetAsString(h, RPMTAG_NEVRA);
+ rpmScript script = xcalloc(1, sizeof(*script));
+ script->tag = tag;
+ script->body = (body != NULL) ? xstrdup(body) : NULL;
+ rasprintf(&script->descr, "%s(%s)", tag2sln(tag), nevra);
+
+ /* macros need to be expanded before possible queryformat */
+ if (script->body && (flags & RPMSCRIPT_EXPAND)) {
+ char *body = rpmExpand(script->body, NULL);
+ free(script->body);
+ script->body = body;
+ }
+ if (script->body && (flags & RPMSCRIPT_QFORMAT)) {
+ /* XXX TODO: handle queryformat errors */
+ char *body = headerFormat(h, script->body, NULL);
+ free(script->body);
+ script->body = body;
+ }
+
+ free(nevra);
+ return script;
+}
+
rpmScript rpmScriptFromTag(Header h, rpmTagVal scriptTag)
{
rpmScript script = NULL;
if (headerIsEntry(h, scriptTag) || headerIsEntry(h, progTag)) {
struct rpmtd_s prog;
- char *nevra = headerGetAsString(h, RPMTAG_NEVRA);
- rpmscriptFlags flags = headerGetNumber(h, getFlagTag(scriptTag));
-
- script = xcalloc(1, sizeof(*script));
- script->tag = scriptTag;
- rasprintf(&script->descr, "%s(%s)", tag2sln(scriptTag), nevra);
- script->body = headerGetAsString(h, scriptTag);
-
- /* macros need to be expanded before possible queryformat */
- if (script->body && (flags & RPMSCRIPT_EXPAND)) {
- char *body = rpmExpand(script->body, NULL);
- free(script->body);
- script->body = body;
- }
- if (script->body && (flags & RPMSCRIPT_QFORMAT)) {
- /* XXX TODO: handle queryformat errors */
- char *body = headerFormat(h, script->body, NULL);
- free(script->body);
- script->body = body;
- }
+
+ script = rpmScriptNew(h, scriptTag,
+ headerGetString(h, scriptTag),
+ headerGetNumber(h, getFlagTag(scriptTag)));
if (headerGet(h, progTag, &prog, (HEADERGET_ALLOC|HEADERGET_ARGV))) {
script->args = prog.data;
}
- free(nevra);
}
return script;
}