Detect lzma magic if it exists, otherwise dumb check for .lzma filename
authorPanu Matilainen <pmatilai@redhat.com>
Sun, 27 Jan 2008 14:11:46 +0000 (16:11 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Sun, 27 Jan 2008 14:11:46 +0000 (16:11 +0200)
- 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...

rpmio/rpmfileutil.c

index e3ff9ee..32e95a6 100644 (file)
@@ -404,12 +404,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 */
@@ -417,6 +416,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;