From b8208b0514e7290fa9301f67bcfebdb4a541bc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20Sz=C3=A1sz?= Date: Sat, 9 Mar 2013 10:14:22 +0400 Subject: [PATCH] Ticket #2976: magic mode is broken in mcview. The bug: If we open a file with F3 from panels, then mc uses "file extension" style open (e.g. archive.sh) and Format/Raw switching is O.K. If we open file in "Raw" mode, or use quick view, mc opens files without "file extension" helpers. Format/Raw switching is broken. In mcview_load() we check magic_mode and detect "compressed" files. If magic mode is on and file is "compressed" we free the current vpath and generate a new vpath with "decompress magic", but nothing else. So, the file name disappear and we see the raw content. After user press F8, mcview reloads the file. Now filename is the "new" magic filename. mcview_load() open the file with the decompress "helper" (using sfs). We see the uncompressed (parsed) content. After user press F8, nothing happend, because original file name is lost. The solution: Remove the old vpath destruction. Open the file with "uncopress magic" if magic_mode is on and file is "compressed". Signed-off-by: Andrew Borodin --- src/viewer/mcviewer.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 93908f3ea..e84bbe1c2 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -375,10 +375,26 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l if (view->magic_mode && (type != COMPRESSION_NONE)) { char *tmp_filename; + vfs_path_t *vpath1; + int fd1; - vfs_path_free (view->filename_vpath); tmp_filename = g_strconcat (file, decompress_extension (type), (char *) NULL); - view->filename_vpath = vfs_path_from_str (tmp_filename); + vpath1 = vfs_path_from_str (tmp_filename); + fd1 = mc_open (vpath1, O_RDONLY | O_NONBLOCK); + if (fd1 == -1) + { + g_snprintf (tmp, sizeof (tmp), _("Cannot open \"%s\" in magic mode\n%s"), + file, unix_error_string (errno)); + mcview_show_error (view, tmp); + } + else + { + mc_close (fd); + fd = fd1; + mc_fstat (fd, &st); + } + vfs_path_free (vpath1); + g_free (tmp_filename); } mcview_set_datasource_file (view, fd, &st);