Use dirname (3) for %dirname
This changes the behaviour of %dirname to something sane. No longer return the argument unchanged if there is no / found. Also handle several cornercases properly. Resolves: #2928
This commit is contained in:
parent
8eac330426
commit
9571e3d9a2
|
@ -6,6 +6,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#ifdef HAVE_SCHED_GETAFFINITY
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
@ -1306,9 +1307,7 @@ static void doFoo(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)
|
|||
b++;
|
||||
} else if (rstreq("dirname", me->name)) {
|
||||
buf = xstrdup(argv[1]);
|
||||
if ((b = strrchr(buf, '/')) != NULL)
|
||||
*b = '\0';
|
||||
b = buf;
|
||||
b = dirname(buf);
|
||||
} else if (rstreq("shrink", me->name)) {
|
||||
/*
|
||||
* shrink body by removing all leading and trailing whitespaces and
|
||||
|
|
|
@ -364,6 +364,15 @@ runroot rpm --eval "%{dirname:dir}"
|
|||
runroot rpm --eval "%{dirname dir}"
|
||||
runroot rpm --eval "%dirname"
|
||||
runroot rpm --eval "%dirname dir"
|
||||
runroot rpm --eval "%dirname /"
|
||||
runroot rpm --eval "%dirname ./"
|
||||
runroot rpm --eval "%dirname .."
|
||||
runroot rpm --eval "%dirname ../"
|
||||
runroot rpm --eval "%dirname ../foo"
|
||||
runroot rpm --eval "%dirname /foo"
|
||||
runroot rpm --eval "%dirname /foo/"
|
||||
runroot rpm --eval "%dirname /foo/foobar"
|
||||
runroot rpm --eval "%dirname /foo/foobar/"
|
||||
runroot rpm --define '%xxx /hello/%%%%/world' --eval '%{dirname:%xxx}'
|
||||
runroot rpm --eval "%{uncompress}"
|
||||
runroot rpm --eval "%{uncompress:}"
|
||||
|
@ -381,10 +390,19 @@ runroot rpm --eval "%shrink %%%%"
|
|||
runroot rpm --eval "%verbose foo"
|
||||
],
|
||||
[0],
|
||||
[
|
||||
dir
|
||||
dir
|
||||
dir
|
||||
[.
|
||||
.
|
||||
.
|
||||
.
|
||||
/
|
||||
.
|
||||
.
|
||||
.
|
||||
..
|
||||
/
|
||||
/
|
||||
/foo
|
||||
/foo
|
||||
/hello/%%
|
||||
|
||||
bar
|
||||
|
|
Loading…
Reference in New Issue