Add %{exists:...} builtin macro for testing file existence
This commit is contained in:
parent
d649c2aa3b
commit
7b25e19803
|
@ -80,6 +80,7 @@ to perform useful operations. The current list is
|
|||
|
||||
%{basename:...} basename(1) macro analogue
|
||||
%{dirname:...} dirname(1) macro analogue
|
||||
%{exists:...} test file existence, expands to 1/0
|
||||
%{suffix:...} expand to suffix part of a file name
|
||||
%{url2path:...} convert url to a local path
|
||||
%{getenv:...} getenv(3) macro analogue
|
||||
|
|
|
@ -625,6 +625,7 @@ static struct builtins_s {
|
|||
{ "dump", doDump, ME_PARSE },
|
||||
{ "echo", doOutput, ME_ARGFUNC },
|
||||
{ "error", doOutput, ME_ARGFUNC },
|
||||
{ "exists", doFoo, ME_ARGFUNC },
|
||||
{ "expand", doExpand, ME_ARGFUNC },
|
||||
{ "expr", doFoo, ME_ARGFUNC },
|
||||
{ "getconfdir", doFoo, ME_FUNC },
|
||||
|
@ -1285,6 +1286,8 @@ doFoo(MacroBuf mb, int chkexist, int negate, rpmMacroEntry me,
|
|||
} else if (rstreq("getncpus", me->name)) {
|
||||
sprintf(buf, "%u", getncpus());
|
||||
b = buf;
|
||||
} else if (rstreq("exists", me->name)) {
|
||||
b = (access(buf, F_OK) == 0) ? "1" : "0";
|
||||
}
|
||||
|
||||
if (b) {
|
||||
|
|
|
@ -782,6 +782,22 @@ runroot rpm --eval '%{verbose:zzz}'
|
|||
])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([%exists macro])
|
||||
AT_KEYWORDS([macros])
|
||||
AT_CHECK([
|
||||
runroot rpm \
|
||||
--eval "%{exists:/data}" \
|
||||
--eval "%{exists:/zzz}" \
|
||||
--eval "%{exists}"
|
||||
],
|
||||
[1],
|
||||
[1
|
||||
0
|
||||
],
|
||||
[error: %exists: argument expected
|
||||
])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([macro with a line starting by "{"])
|
||||
AT_KEYWORDS([macros])
|
||||
AT_CHECK([
|
||||
|
|
Loading…
Reference in New Issue