From 15e9e1ff64aaf986ab0dd97b9b12c3d4fb22a484 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 7 May 2008 11:12:17 +0300 Subject: Simplify doPatch() - use %{uncompress} macro to pass files to patch always - gains support for lzma patches for free --- build/parsePrep.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/build/parsePrep.c b/build/parsePrep.c index e64080992..e3a76869a 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -69,8 +69,7 @@ static char *doPatch(rpmSpec spec, int c, int strip, const char *db, char *arg_fuzz = NULL; char *args = NULL; struct Source *sp; - char *patcher; - rpmCompressedMagic compressed = COMPRESSED_NOT; + char *patchcmd; for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMBUILD_ISPATCH) && (sp->num == c)) { @@ -84,8 +83,11 @@ static char *doPatch(rpmSpec spec, int c, int strip, const char *db, fn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); - /* XXX On non-build parse's, file cannot be stat'd or read */ - if (!spec->force && (rpmFileIsCompressed(fn, &compressed) || checkOwners(fn))) { + /* + * FIXME: On non-build parse's, file cannot be stat'd or read but + * %{uncompress} doesn't know that so we get errors on non-existent files. + */ + if (!spec->force && checkOwners(fn)) { fn = _free(fn); return NULL; } @@ -102,35 +104,20 @@ static char *doPatch(rpmSpec spec, int c, int strip, const char *db, rasprintf(&arg_fuzz, " --fuzz=%d", fuzz); } else arg_fuzz = xstrdup(""); - rasprintf(&args, "%s%s%s%s", arg_backup, arg_fuzz, reverse ? " -R" : "", removeEmpties ? " -E" : ""); - free(arg_fuzz); - free(arg_backup); + rasprintf(&args, "-s -p%d %s%s%s%s", strip, arg_backup, arg_fuzz, + reverse ? " -R" : "", + removeEmpties ? " -E" : ""); - patcher = rpmGetPath("%{__patch}", NULL); - if (compressed) { - char *zipper = rpmGetPath( - (compressed == COMPRESSED_BZIP2 ? "%{__bzip2}" : "%{__gzip}"), - NULL); - - rasprintf(&buf, - "echo \"Patch #%d (%s):\"\n" - "%s -d < '%s' | %s -p%d %s -s\n" - "STATUS=$?\n" - "if [ $STATUS -ne 0 ]; then\n" - " exit $STATUS\n" - "fi", - c, (const char *) basename(fn), - zipper, patcher, - fn, strip, args); - zipper = _free(zipper); - } else { - rasprintf(&buf, - "echo \"Patch #%d (%s):\"\n" - "%s -p%d %s -s < '%s'", c, (const char *) basename(fn), - patcher, strip, args, fn); - } + patchcmd = rpmExpand("%{uncompress: ", fn, "} | %{__patch} ", args, NULL); - patcher = _free(patcher); + free(arg_fuzz); + free(arg_backup); + free(args); + + rasprintf(&buf, "echo \"Patch #%d (%s):\"\n" + "%s\n", + strip, basename(fn), patchcmd); + fn = _free(fn); return buf; } -- cgit v1.2.3