From bd95f71a6b889fc27f5f474c41159c21549ef315 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 4 Sep 2009 23:58:15 +0300 Subject: [PATCH] Some little bugfixies for xz and lzma archives: * Increase number of reading butes by one for better analyzation of compression type. * Add recognize lzma archive by extention. Signed-off-by: Slava Zanko --- src/util.c | 27 ++++++++++++++++++--------- src/util.h | 2 +- src/viewer/mcviewer.c | 2 +- vfs/cpio.c | 2 +- vfs/tar.c | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/util.c b/src/util.c index cc0b5d4b4..12b7ef7ed 100644 --- a/src/util.c +++ b/src/util.c @@ -855,7 +855,7 @@ get_current_wd (char *buffer, int size) #endif /* !USE_VFS */ enum compression_type -get_compression_type (int fd) +get_compression_type (int fd, const char * name) { unsigned char magic[16]; @@ -920,14 +920,23 @@ get_compression_type (int fd) } /* XZ compression magic */ - if (magic[0] == 0xFD - && magic[1] == 0x37 - && magic[2] == 0x7A - && magic[3] == 0x58 - && magic[4] == 0x5A - && magic[5] == 0x00) { - return COMPRESSION_XZ; - } + if (mc_read(fd, (char *) magic+5, 1) == 1) + { + if ( + magic[0] == 0xFD + && magic[1] == 0x37 + && magic[2] == 0x7A + && magic[3] == 0x58 + && magic[4] == 0x5A + && magic[5] == 0x00 + ){ + return COMPRESSION_XZ; + } + } + + /* HACK: we must belive to extention of LZMA file :) ...*/ + if (strlen(name) > 5 && strcmp(&name[strlen(name)-5],".lzma") == 0) + return COMPRESSION_LZMA; return COMPRESSION_NONE; } diff --git a/src/util.h b/src/util.h index 17df3b57d..69cbe18ec 100644 --- a/src/util.h +++ b/src/util.h @@ -190,7 +190,7 @@ enum compression_type { /* Looks for ``magic'' bytes at the start of the VFS file to guess the * compression type. Side effect: modifies the file position. */ -enum compression_type get_compression_type (int fd); +enum compression_type get_compression_type (int fd, const char*); const char *decompress_extension (int type); /* Hook functions */ diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index fac7a85b2..c93d3bff3 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -348,7 +348,7 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l /* Must be one of those nice files that grow (/proc) */ mcview_set_datasource_vfs_pipe (view, fd); } else { - type = get_compression_type (fd); + type = get_compression_type (fd, file); if (view->magic_mode && (type != COMPRESSION_NONE)) { g_free (view->filename); diff --git a/vfs/cpio.c b/vfs/cpio.c index 983197605..f9fa1a820 100644 --- a/vfs/cpio.c +++ b/vfs/cpio.c @@ -175,7 +175,7 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, mc_stat (name, &(super->u.arch.st)); super->u.arch.type = CPIO_UNKNOWN; - type = get_compression_type (fd); + type = get_compression_type (fd, name); if (type != COMPRESSION_NONE) { char *s; diff --git a/vfs/tar.c b/vfs/tar.c index f33bb33b6..e0b6a20b7 100644 --- a/vfs/tar.c +++ b/vfs/tar.c @@ -243,7 +243,7 @@ tar_open_archive_int (struct vfs_class *me, const char *name, archive->u.arch.type = TAR_UNKNOWN; /* Find out the method to handle this tar file */ - type = get_compression_type (result); + type = get_compression_type (result, name); mc_lseek (result, 0, SEEK_SET); if (type != COMPRESSION_NONE) { char *s; -- 2.11.4.GIT