added support for .xz/.lzma compressed sources and patches

This also fixes some bugs:
- %uncompress macro never worked;
- %patch -s -b .orig never worked.
This commit is contained in:
Alexey Tourbin 2009-09-24 11:09:30 +04:00
parent 222b98db0b
commit 19e6de9d5e
7 changed files with 152 additions and 163 deletions

View File

@ -239,9 +239,9 @@ doxygen @WITH_APIDOCS_TARGET@: Doxyfile
- [ X"@__DOXYGEN@" != Xno ] && @__DOXYGEN@
ctags:
find . -type f -name "*.[ch]*" | xargs @CTAGS@
find . -type f -name "*.[ch]*" | xargs ctags
cscope:
@CSCOPE@ -b -R
cscope -b -R
cref: ctags cscope

View File

@ -71,13 +71,7 @@ static int checkOwners(const char * urlfn)
fileSystem@*/
/*@modifies rpmGlobalMacroContext, fileSystem @*/
{
const char *fn, *urlfn, *patcher;
static char buf[BUFSIZ];
char args[BUFSIZ];
struct Source *sp;
rpmCompressedMagic compressed = COMPRESSED_NOT;
int urltype;
for (sp = spec->sources; sp != NULL; sp = sp->next) {
if ((sp->flags & RPMBUILD_ISPATCH) && (sp->num == c)) {
break;
@ -88,33 +82,30 @@ static int checkOwners(const char * urlfn)
return NULL;
}
urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
const char *urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
args[0] = '\0';
char args[BUFSIZ];
sprintf(args, "-p%d", strip);
if (silent)
strcat(args, " -s");
if (db) {
#if HAVE_OLDPATCH_21 == 0
strcat(args, "-b ");
#endif
strcat(args, "--suffix ");
strcat(args, " -b --suffix ");
strcat(args, db);
}
if (reverse) {
if (reverse)
strcat(args, " -R");
}
if (removeEmpties) {
if (removeEmpties)
strcat(args, " -E");
}
rpmCompressedMagic compressed = COMPRESSED_NOT;
/* XXX On non-build parse's, file cannot be stat'd or read */
if (!spec->force && (isCompressed(urlfn, &compressed) || checkOwners(urlfn))) {
urlfn = _free(urlfn);
return NULL;
}
fn = NULL;
urltype = urlPath(urlfn, &fn);
const char *fn = NULL;
int urltype = urlPath(urlfn, &fn);
switch (urltype) {
case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
@ -127,40 +118,40 @@ static int checkOwners(const char * urlfn)
/*@notreached@*/ break;
}
patcher = rpmGetPath("%{__patch}", NULL);
const char *t;
const char *patcher = rpmGetPath("%{__patch}", NULL);
char cmd[BUFSIZ];
if (compressed != COMPRESSED_NOT) {
const char *zipper, *zipper_opts;
switch ( compressed )
{
switch (compressed) {
default: /* XXX can't happen */
case COMPRESSED_OTHER:
t = "%{__gzip} -dc";
break;
case COMPRESSED_BZIP2:
zipper = "%{_bzip2bin}";
zipper_opts = "-dc";
t = "%{__bzip2} -dc";
break;
case COMPRESSED_ZIP:
zipper = "%{_unzipbin}";
zipper_opts = "-p";
t = "%{__unzip} -qq -p";
break;
default:
zipper = "%{_gzipbin}";
zipper_opts = "-dc";
case COMPRESSED_LZMA:
t = "%{__lzma} -dc";
break;
case COMPRESSED_XZ:
t = "%{__xz} -dc";
break;
}
zipper = rpmGetPath( zipper, NULL );
snprintf(buf, sizeof(buf),
"echo \"Patch #%d (%s):\"\n"
"%s %s %s |%s -p%d %s\n",
c, /*@-unrecog@*/ (const char *) basename(fn), /*@=unrecog@*/
zipper, zipper_opts, fn, patcher, strip, args);
const char *zipper = rpmGetPath(t, NULL);
sprintf(cmd, "%s '%s' | %s %s\n", zipper, fn, patcher, args);
zipper = _free(zipper);
} else {
snprintf(buf, sizeof(buf),
"echo \"Patch #%d (%s):\"\n"
"%s -p%d %s < %s", c, (const char *) basename(fn),
patcher, strip, args, fn);
sprintf(cmd, "%s %s < '%s'\n", patcher, args, fn);
}
patcher = _free(patcher);
static char buf[BUFSIZ];
sprintf(buf, "echo 'Patch #%d (%s):'\n", c, basename(fn));
strcat(buf, cmd);
urlfn = _free(urlfn);
return buf;
}
@ -177,12 +168,7 @@ static int checkOwners(const char * urlfn)
fileSystem@*/
/*@modifies rpmGlobalMacroContext, fileSystem @*/
{
const char *fn, *urlfn;
static char buf[BUFSIZ];
struct Source *sp;
rpmCompressedMagic compressed = COMPRESSED_NOT;
int urltype;
for (sp = spec->sources; sp != NULL; sp = sp->next) {
if ((sp->flags & RPMBUILD_ISSOURCE) && (sp->num == c)) {
break;
@ -193,7 +179,7 @@ static int checkOwners(const char * urlfn)
return NULL;
}
urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
const char *urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
#ifdef AUTOFETCH_NOT /* XXX don't expect this code to be enabled */
/* XXX
@ -215,14 +201,15 @@ static int checkOwners(const char * urlfn)
}
#endif
rpmCompressedMagic compressed = COMPRESSED_NOT;
/* XXX On non-build parse's, file cannot be stat'd or read */
if (!spec->force && (isCompressed(urlfn, &compressed) || checkOwners(urlfn))) {
urlfn = _free(urlfn);
return NULL;
}
fn = NULL;
urltype = urlPath(urlfn, &fn);
const char *fn = NULL;
int urltype = urlPath(urlfn, &fn);
switch (urltype) {
case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
@ -235,49 +222,49 @@ static int checkOwners(const char * urlfn)
/*@notreached@*/ break;
}
const char *t;
if (rpmIsVerbose() && !quietly)
t = "%{__tar} -xvvf";
else
t = "%{__tar} -xf";
const char *tar = rpmGetPath(t, NULL);
char cmd[BUFSIZ];
if (compressed != COMPRESSED_NOT) {
/*@-internalglobs@*/ /* FIX: shrug */
const char *taropts = (rpmIsVerbose() && !quietly) ? "-xvvf -" : "-xf -";
/*@=internalglobs@*/
const char *zipper, *zipper_opts, *tarprog = "%{__tar}";
switch ( compressed )
{
switch (compressed) {
default: /* XXX can't happen */
case COMPRESSED_OTHER:
t = "%{__gzip} -dc";
break;
case COMPRESSED_BZIP2:
zipper = "%{_bzip2bin}";
zipper_opts = "-dc";
t = "%{__bzip2} -dc";
break;
case COMPRESSED_ZIP:
zipper = "%{_unzipbin}";
zipper_opts = (rpmIsVerbose() && !quietly) ? "" : "-qq";
tarprog = NULL;
if (rpmIsVerbose() && !quietly)
t = "%{__unzip}";
else
t = "%{__unzip} -qq";
break;
default:
zipper = "%{_gzipbin}";
zipper_opts = "-dc";
case COMPRESSED_LZMA:
t = "%{__lzma} -dc";
break;
case COMPRESSED_XZ:
t = "%{__xz} -dc";
break;
}
if ( tarprog )
tarprog = rpmGetPath( tarprog, NULL );
zipper = rpmGetPath( zipper, NULL );
snprintf(buf, sizeof(buf),
"echo \"Source #%d (%s):\"\n"
"%s %s %s %s%s %s\n",
c, /*@-unrecog@*/ (const char *) basename(fn), /*@=unrecog@*/
zipper, zipper_opts, fn,
(tarprog?"|":""), (tarprog?tarprog:""), (tarprog?taropts:""));
zipper = _free( zipper );
tarprog = _free( tarprog );
const char *zipper = rpmGetPath(t, NULL);
if (compressed == COMPRESSED_ZIP)
sprintf(cmd, "%s '%s'\n", zipper, fn);
else
sprintf(cmd, "%s '%s' | %s -\n", zipper, fn, tar);
zipper = _free(zipper);
} else {
const char *taropts = (rpmIsVerbose() && !quietly) ? "-xvvf" : "-xf";
const char *tarprog = rpmGetPath( "%{__tar}", NULL );
snprintf( buf, sizeof(buf),
"echo \"Source #%d (%s):\"\n"
"%s %s %s",
c, /*@-unrecog@*/ (const char *) basename(fn), /*@=unrecog@*/
tarprog, taropts, fn );
tarprog = _free( tarprog );
sprintf(cmd, "%s '%s'\n", tar, fn);
}
tar = _free(tar);
static char buf[BUFSIZ];
sprintf(buf, "echo 'Source #%d (%s):'\n", c, basename(fn));
strcat(buf, cmd);
urlfn = _free(urlfn);
return buf;

View File

@ -62,9 +62,6 @@ export RPMUSER RPMGROUP
AC_SUBST(RPMUSER)
AC_SUBST(RPMGROUP)
AC_PATH_PROG(CTAGS, ctags, /bin/true)
AC_PATH_PROG(CSCOPE, cscope, /bin/true)
dnl
dnl This now uses libtool. Put
dnl LDFLAGS_STATIC="-all"
@ -199,15 +196,20 @@ AC_PATH_PROG(__CHGRP, chgrp, /bin/chgrp, $MYPATH)
AC_PATH_PROG(__CHMOD, chmod, /bin/chmod, $MYPATH)
AC_PATH_PROG(__CHOWN, chown, /bin/chown, $MYPATH)
AC_PATH_PROG(__CP, cp, /bin/cp, $MYPATH)
AC_PATH_PROG(__CPIO, cpio, /bin/cpio, $MYPATH)
AC_PATH_PROG(__FILE, file, /usr/bin/file, $MYPATH)
AC_PATH_PROG(__GPG, gpg, /usr/bin/gpg, $MYPATH)
AC_PATH_PROG(__GREP, grep, /bin/grep, $MYPATH)
AC_PATH_PROG(GZIPBIN, gzip, /bin/gzip, $MYPATH)
AC_PATH_PROG(BZIP2BIN, bzip2, /bin/bzip2, $MYPATH)
AC_PATH_PROG(UNZIPBIN, unzip, /usr/bin/unzip, $MYPATH)
AC_PATH_PROG(__SUBST, subst, /usr/bin/subst, $MYPATH)
dnl Archiving and compression programs
AC_PATH_PROG(__TAR, tar, /bin/tar, $MYPATH)
AC_PATH_PROG(__CPIO, cpio, /bin/cpio, $MYPATH)
AC_PATH_PROG(__GZIP, gzip, /bin/gzip, $MYPATH)
AC_PATH_PROG(__BZIP2, bzip2, /bin/bzip2, $MYPATH)
AC_PATH_PROG(__UNZIP, unzip, /usr/bin/unzip, $MYPATH)
AC_PATH_PROG(__LZMA, lzms, /usr/bin/lzma, $MYPATH)
AC_PATH_PROG(__XZ, xz, /usr/bin/xz, $MYPATH)
AC_PATH_PROG(__ID, id, /usr/bin/id, $MYPATH)
AC_MSG_CHECKING(checking whether id supports -u)
if ${__ID} -u 2>&1 > /dev/null ; then
@ -226,16 +228,6 @@ AC_PATH_PROG(__MAKE, make, /usr/bin/make, $MYPATH)
AC_PATH_PROG(__MKDIR, mkdir, /bin/mkdir, $MYPATH)
AC_PATH_PROG(__MV, mv, /bin/mv, $MYPATH)
AC_PATH_PROG(__PATCH, patch, /usr/bin/patch, $MYPATH)
AC_MSG_CHECKING(old version of patch)
PATCHVERSION=`patch --version 2>&1`
if test "$PATCHVERSION" = "Patch version 2.1"; then
AC_DEFINE(HAVE_OLDPATCH_21, 1,
[Define if the patch call you'll be using is 2.1 or older])
AC_MSG_RESULT(patch older then 2.2 found)
else
AC_MSG_RESULT(patch later then 2.2 found)
fi
AC_PATH_PROG(__PERL, perl, /usr/bin/perl, $MYPATH)
AC_PATH_PROG(PGPBIN, pgp, /usr/bin/pgp, $MYPATH)
@ -244,7 +236,6 @@ AC_PATH_PROG(__RM, rm, /bin/rm, $MYPATH)
AC_PATH_PROG(__RSH, rsh, /usr/bin/rsh, $MYPATH)
AC_PATH_PROG(__SED, sed, /bin/sed, $MYPATH)
AC_PATH_PROG(__SSH, ssh, /usr/bin/ssh, $MYPATH)
AC_PATH_PROG(__TAR, tar, /bin/tar, $MYPATH)
AC_PATH_PROG(__LD, ld, /usr/bin/ld, $MYPATH)
AC_PATH_PROG(__NM, nm, /usr/bin/nm, $MYPATH)

View File

@ -33,17 +33,14 @@
# ---- Generally useful path macros.
#
%__awk @AWK@
%__bzip2 @BZIP2BIN@
%__cat @__CAT@
%__chgrp @__CHGRP@
%__chmod @__CHMOD@
%__chown @__CHOWN@
%__cp @__CP@
%__cpio @__CPIO@
%__file @__FILE@
%__gpg @__GPG@
%__grep @__GREP@
%__gzip @GZIPBIN@
%__id @__ID@
%__install @__INSTALL@
%__install_info @__INSTALL_INFO@
@ -61,8 +58,18 @@
%__sed @__SED@
%__ssh @__SSH@
%__subst @__SUBST@
#==============================================================================
# ---- Archiving and compression programs.
#
#
%__tar @__TAR@
%__unzip @UNZIPBIN@
%__cpio @__CPIO@
%__gzip @__GZIP@
%__bzip2 @__BZIP2@
%__unzip @__UNZIP@
%__lzma @__LZMA@
%__xz @__XZ@
#==============================================================================
# ---- Build system path macros.
@ -99,9 +106,6 @@
# The interpreter used for build scriptlets.
%_buildshell /bin/sh
# The path to the bzip2 executable (legacy, use %{__bzip2} instead).
%_bzip2bin %{__bzip2}
# The location of the rpm database file(s).
%_dbpath %{_var}/lib/rpm
@ -129,9 +133,6 @@
#%_fixperms %{__chmod} -Rf @FIXPERMS@
#
# The path to the gzip executable (legacy, use %{__gzip} instead).
%_gzipbin %{__gzip}
# The number of changelog entries kept when installing (legacy, unused in
# rpm-4.0.1 and later).
%_instchangelog 5
@ -169,9 +170,6 @@
# Path to top of spec/source/patch area.
%_topsrcdir %{_topdir}
# The path to the unzip executable (legacy, use %{__unzip} instead).
%_unzipbin %{__unzip}
#==============================================================================
# ---- Optional rpmrc macros.
# Macros that are initialized as a side effect of rpmrc and/or spec

View File

@ -223,13 +223,13 @@ touch config.rpath
gettextize --force --quiet
install -pv -m644 /usr/share/gettext/intl/Makevars* po/Makevars
autoreconf -fisv -I m4
export \
ac_cv_path_CTAGS=/usr/bin/ctags \
ac_cv_path_UNZIPBIN=/usr/bin/unzip \
ac_cv_path___CPIO=/bin/cpio \
ac_cv_path___GPG=/usr/bin/gpg \
ac_cv_path___SSH=/usr/bin/ssh \
#
# avoid extra build dependencies
export ac_cv_path___CPIO=/bin/cpio
export ac_cv_path___UNZIP=/usr/bin/unzip
export ac_cv_path___LZMA=/usr/bin/lzma
export ac_cv_path___XZ=/usr/bin/xz
export ac_cv_path___GPG=/usr/bin/gpg
export ac_cv_path___SSH=/usr/bin/ssh
%configure \
%{?_with_python} %{?_without_python} \
%{?_with_apidocs} %{?_without_apidocs} \

View File

@ -1092,17 +1092,23 @@ doFoo(MacroBuf mb, int negate, const char * f, size_t fn,
#endif
switch(compressed) {
default:
case 0: /* COMPRESSED_NOT */
sprintf(be, "%%_cat %s", b);
case COMPRESSED_NOT:
sprintf(be, "%%__cat '%s'", b);
break;
case 1: /* COMPRESSED_OTHER */
sprintf(be, "%%_gzip -dc %s", b);
case COMPRESSED_OTHER:
sprintf(be, "%%__gzip -dc '%s'", b);
break;
case 2: /* COMPRESSED_BZIP2 */
sprintf(be, "%%_bzip2 %s", b);
case COMPRESSED_BZIP2:
sprintf(be, "%%__bzip2 -dc '%s'", b);
break;
case 3: /* COMPRESSED_ZIP */
sprintf(be, "%%_unzip %s", b);
case COMPRESSED_ZIP:
sprintf(be, "%%__unzip -qq -p '%s'", b);
break;
case COMPRESSED_LZMA:
sprintf(be, "%%__lzma -dc '%s'", b);
break;
case COMPRESSED_XZ:
sprintf(be, "%%__xz -dc '%s'", b);
break;
}
b = be;
@ -1766,26 +1772,24 @@ rpmFreeMacros(MacroContext mc)
/* =============================================================== */
int isCompressed(const char * file, rpmCompressedMagic * compressed)
{
FD_t fd;
ssize_t nb;
int rc = -1;
unsigned char magic[4];
*compressed = COMPRESSED_NOT;
fd = Fopen(file, "r.ufdio");
FD_t fd = Fopen(file, "r.ufdio");
if (fd == NULL || Ferror(fd)) {
/* XXX Fstrerror */
rpmError(RPMERR_BADSPEC, _("File %s: %s\n"), file, Fstrerror(fd));
if (fd) (void) Fclose(fd);
return 1;
}
nb = Fread(magic, sizeof(magic[0]), sizeof(magic), fd);
int rc = -1;
unsigned char magic[8];
ssize_t nb = Fread(magic, sizeof(magic[0]), sizeof(magic), fd);
if (nb < 0) {
rpmError(RPMERR_BADSPEC, _("File %s: %s\n"), file, Fstrerror(fd));
rc = 1;
} else if (nb < sizeof(magic)) {
rpmError(RPMERR_BADSPEC, _("File %s is smaller than %u bytes\n"),
rpmMessage(RPMMESS_WARNING, _("File %s is smaller than %u bytes\n"),
file, (unsigned)sizeof(magic));
rc = 0;
}
@ -1793,18 +1797,25 @@ int isCompressed(const char * file, rpmCompressedMagic * compressed)
if (rc >= 0)
return rc;
if ((magic[0] == 'B') && (magic[1] == 'Z')) {
*compressed = COMPRESSED_BZIP2;
} else if ((magic[0] == 0120) && (magic[1] == 0113) &&
(magic[2] == 0003) && (magic[3] == 0004)) { /* pkzip */
*compressed = COMPRESSED_ZIP;
} else if (((magic[0] == 0037) && (magic[1] == 0213)) || /* gzip */
((magic[0] == 0037) && (magic[1] == 0236)) || /* old gzip */
((magic[0] == 0037) && (magic[1] == 0036)) || /* pack */
((magic[0] == 0037) && (magic[1] == 0240)) || /* SCO lzh */
((magic[0] == 0037) && (magic[1] == 0235)) /* compress */
) {
*compressed = COMPRESSED_OTHER;
#define BT(s,t) \
if (memcmp(s,magic,sizeof(s)-1)==0) \
{ *compressed = COMPRESSED_##t; return 0; }
BT("BZh", BZIP2);
BT("PK\003\004", ZIP);
BT("\037\213", OTHER); // gizp
BT("\037\236", OTHER); // old gzip
BT("\037\036", OTHER); // pack
BT("\037\240", OTHER); // SCO lzh
BT("\037\235", OTHER); // compress
BT("\3757zXZ\0", XZ);
#undef BT
/* LZMA has no magic */
if (magic[0] < 0xE1 && magic[1] == 0) {
const char *ext = strrchr(file, '.');
if (ext)
if (strcmp(ext, ".lzma") == 0 || strcmp(ext, ".tlz") == 0)
*compressed = COMPRESSED_LZMA;
}
return 0;

View File

@ -152,7 +152,9 @@ typedef enum rpmCompressedMagic_e {
COMPRESSED_NOT = 0, /*!< not compressed */
COMPRESSED_OTHER = 1, /*!< gzip can handle */
COMPRESSED_BZIP2 = 2, /*!< bzip2 can handle */
COMPRESSED_ZIP = 3 /*!< unzip can handle */
COMPRESSED_ZIP = 3, /*!< unzip can handle */
COMPRESSED_LZMA = 4, /*!< lzma can handle */
COMPRESSED_XZ = 5 /*!< xz can handle */
} rpmCompressedMagic;
/**