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@ - [ X"@__DOXYGEN@" != Xno ] && @__DOXYGEN@
ctags: ctags:
find . -type f -name "*.[ch]*" | xargs @CTAGS@ find . -type f -name "*.[ch]*" | xargs ctags
cscope: cscope:
@CSCOPE@ -b -R cscope -b -R
cref: ctags cscope cref: ctags cscope

View File

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

View File

@ -62,9 +62,6 @@ export RPMUSER RPMGROUP
AC_SUBST(RPMUSER) AC_SUBST(RPMUSER)
AC_SUBST(RPMGROUP) AC_SUBST(RPMGROUP)
AC_PATH_PROG(CTAGS, ctags, /bin/true)
AC_PATH_PROG(CSCOPE, cscope, /bin/true)
dnl dnl
dnl This now uses libtool. Put dnl This now uses libtool. Put
dnl LDFLAGS_STATIC="-all" 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(__CHMOD, chmod, /bin/chmod, $MYPATH)
AC_PATH_PROG(__CHOWN, chown, /bin/chown, $MYPATH) AC_PATH_PROG(__CHOWN, chown, /bin/chown, $MYPATH)
AC_PATH_PROG(__CP, cp, /bin/cp, $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(__FILE, file, /usr/bin/file, $MYPATH)
AC_PATH_PROG(__GPG, gpg, /usr/bin/gpg, $MYPATH) AC_PATH_PROG(__GPG, gpg, /usr/bin/gpg, $MYPATH)
AC_PATH_PROG(__GREP, grep, /bin/grep, $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) 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_PATH_PROG(__ID, id, /usr/bin/id, $MYPATH)
AC_MSG_CHECKING(checking whether id supports -u) AC_MSG_CHECKING(checking whether id supports -u)
if ${__ID} -u 2>&1 > /dev/null ; then 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(__MKDIR, mkdir, /bin/mkdir, $MYPATH)
AC_PATH_PROG(__MV, mv, /bin/mv, $MYPATH) AC_PATH_PROG(__MV, mv, /bin/mv, $MYPATH)
AC_PATH_PROG(__PATCH, patch, /usr/bin/patch, $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(__PERL, perl, /usr/bin/perl, $MYPATH)
AC_PATH_PROG(PGPBIN, pgp, /usr/bin/pgp, $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(__RSH, rsh, /usr/bin/rsh, $MYPATH)
AC_PATH_PROG(__SED, sed, /bin/sed, $MYPATH) AC_PATH_PROG(__SED, sed, /bin/sed, $MYPATH)
AC_PATH_PROG(__SSH, ssh, /usr/bin/ssh, $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(__LD, ld, /usr/bin/ld, $MYPATH)
AC_PATH_PROG(__NM, nm, /usr/bin/nm, $MYPATH) AC_PATH_PROG(__NM, nm, /usr/bin/nm, $MYPATH)

View File

@ -33,17 +33,14 @@
# ---- Generally useful path macros. # ---- Generally useful path macros.
# #
%__awk @AWK@ %__awk @AWK@
%__bzip2 @BZIP2BIN@
%__cat @__CAT@ %__cat @__CAT@
%__chgrp @__CHGRP@ %__chgrp @__CHGRP@
%__chmod @__CHMOD@ %__chmod @__CHMOD@
%__chown @__CHOWN@ %__chown @__CHOWN@
%__cp @__CP@ %__cp @__CP@
%__cpio @__CPIO@
%__file @__FILE@ %__file @__FILE@
%__gpg @__GPG@ %__gpg @__GPG@
%__grep @__GREP@ %__grep @__GREP@
%__gzip @GZIPBIN@
%__id @__ID@ %__id @__ID@
%__install @__INSTALL@ %__install @__INSTALL@
%__install_info @__INSTALL_INFO@ %__install_info @__INSTALL_INFO@
@ -61,8 +58,18 @@
%__sed @__SED@ %__sed @__SED@
%__ssh @__SSH@ %__ssh @__SSH@
%__subst @__SUBST@ %__subst @__SUBST@
#==============================================================================
# ---- Archiving and compression programs.
#
#
%__tar @__TAR@ %__tar @__TAR@
%__unzip @UNZIPBIN@ %__cpio @__CPIO@
%__gzip @__GZIP@
%__bzip2 @__BZIP2@
%__unzip @__UNZIP@
%__lzma @__LZMA@
%__xz @__XZ@
#============================================================================== #==============================================================================
# ---- Build system path macros. # ---- Build system path macros.
@ -99,9 +106,6 @@
# The interpreter used for build scriptlets. # The interpreter used for build scriptlets.
%_buildshell /bin/sh %_buildshell /bin/sh
# The path to the bzip2 executable (legacy, use %{__bzip2} instead).
%_bzip2bin %{__bzip2}
# The location of the rpm database file(s). # The location of the rpm database file(s).
%_dbpath %{_var}/lib/rpm %_dbpath %{_var}/lib/rpm
@ -129,9 +133,6 @@
#%_fixperms %{__chmod} -Rf @FIXPERMS@ #%_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 # The number of changelog entries kept when installing (legacy, unused in
# rpm-4.0.1 and later). # rpm-4.0.1 and later).
%_instchangelog 5 %_instchangelog 5
@ -169,9 +170,6 @@
# Path to top of spec/source/patch area. # Path to top of spec/source/patch area.
%_topsrcdir %{_topdir} %_topsrcdir %{_topdir}
# The path to the unzip executable (legacy, use %{__unzip} instead).
%_unzipbin %{__unzip}
#============================================================================== #==============================================================================
# ---- Optional rpmrc macros. # ---- Optional rpmrc macros.
# Macros that are initialized as a side effect of rpmrc and/or spec # 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 gettextize --force --quiet
install -pv -m644 /usr/share/gettext/intl/Makevars* po/Makevars install -pv -m644 /usr/share/gettext/intl/Makevars* po/Makevars
autoreconf -fisv -I m4 autoreconf -fisv -I m4
export \ # avoid extra build dependencies
ac_cv_path_CTAGS=/usr/bin/ctags \ export ac_cv_path___CPIO=/bin/cpio
ac_cv_path_UNZIPBIN=/usr/bin/unzip \ export ac_cv_path___UNZIP=/usr/bin/unzip
ac_cv_path___CPIO=/bin/cpio \ export ac_cv_path___LZMA=/usr/bin/lzma
ac_cv_path___GPG=/usr/bin/gpg \ export ac_cv_path___XZ=/usr/bin/xz
ac_cv_path___SSH=/usr/bin/ssh \ export ac_cv_path___GPG=/usr/bin/gpg
# export ac_cv_path___SSH=/usr/bin/ssh
%configure \ %configure \
%{?_with_python} %{?_without_python} \ %{?_with_python} %{?_without_python} \
%{?_with_apidocs} %{?_without_apidocs} \ %{?_with_apidocs} %{?_without_apidocs} \

View File

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

View File

@ -152,7 +152,9 @@ typedef enum rpmCompressedMagic_e {
COMPRESSED_NOT = 0, /*!< not compressed */ COMPRESSED_NOT = 0, /*!< not compressed */
COMPRESSED_OTHER = 1, /*!< gzip can handle */ COMPRESSED_OTHER = 1, /*!< gzip can handle */
COMPRESSED_BZIP2 = 2, /*!< bzip2 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; } rpmCompressedMagic;
/** /**