summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-03-04 08:28:10 +0200
committerPanu Matilainen <pmatilai@redhat.com>2008-03-04 08:28:10 +0200
commit64f405996f15c0f3f923081cbd63f141bc418bb3 (patch)
treefe37e5b4d1f8acaefda59703a7cd560b3a41b4bb
parent3b339dbaf4917a402aa705662a0de82c31928296 (diff)
downloadrpm-64f405996f15c0f3f923081cbd63f141bc418bb3.tar.gz
Detect lzma magic if it exists, otherwise dumb check for .lzma filename
- Newer lzma-utils make a magic header in archives, current stable versions don't. Guessing based on common compression flags used by current lzma versions is feeble and futile...
-rw-r--r--rpmio/macro.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index b42669f8d..40c1546d8 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -2066,6 +2066,15 @@ rpmFreeMacros(MacroContext mc)
}
/*@=globstate@*/
+static int rpmFileHasSuffix(const char *path, const char *suffix)
+{
+ size_t plen = strlen(path);
+ size_t slen = strlen(suffix);
+ return (plen >= slen &&
+ strcmp(path+plen-slen, suffix) == 0);
+}
+
+
/* =============================================================== */
int isCompressed(const char * file, rpmCompressedMagic * compressed)
{
@@ -2103,12 +2112,11 @@ int isCompressed(const char * file, rpmCompressedMagic * compressed)
} else if ((magic[0] == 0120) && (magic[1] == 0113) &&
(magic[2] == 0003) && (magic[3] == 0004)) { /* pkzip */
*compressed = COMPRESSED_ZIP;
- } else if ((magic[ 9] == 0x00) && (magic[10] == 0x00) &&
- (magic[11] == 0x00) && (magic[12] == 0x00)) {
- /* lzma */
- /* FIXME: lzma doesn't have a magic,
- * consider to additionally check the filename */
- *compressed = COMPRESSED_LZMA;
+ } else if ((magic[0] == 0xff) && (magic[1] == 0x4c) &&
+ (magic[2] == 0x5a) && (magic[3] == 0x4d) &&
+ (magic[4] == 0x41) && (magic[5] == 0x00)) {
+ /* new style lzma with magic */
+ *compressed = COMPRESSED_LZMA;
} else if (((magic[0] == 0037) && (magic[1] == 0213)) || /* gzip */
((magic[0] == 0037) && (magic[1] == 0236)) || /* old gzip */
((magic[0] == 0037) && (magic[1] == 0036)) || /* pack */
@@ -2116,6 +2124,8 @@ int isCompressed(const char * file, rpmCompressedMagic * compressed)
((magic[0] == 0037) && (magic[1] == 0235)) /* compress */
) {
*compressed = COMPRESSED_OTHER;
+ } else if (rpmFileHasSuffix(file, ".lzma")) {
+ *compressed = COMPRESSED_LZMA;
}
return rc;