changeset 14679:ba010fa2bcba v8.1.0352

patch 8.1.0352: browsing compressed tar files does not always work commit https://github.com/vim/vim/commit/d4a1aabe372ccb95aec968f4d54503231b1f956c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 8 15:10:34 2018 +0200 patch 8.1.0352: browsing compressed tar files does not always work Problem: Browsing compressed tar files does not always work. Solution: Use the "file" command to get the compression type.
author Christian Brabandt <cb@256bit.org>
date Sat, 08 Sep 2018 15:15:08 +0200
parents 39dbe2da8812
children ac64c88a6033
files runtime/autoload/tar.vim src/version.c
diffstat 2 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/autoload/tar.vim
+++ b/runtime/autoload/tar.vim
@@ -153,15 +153,14 @@ fun! tar#Browse(tarfile)
    let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e')
   endif
 
-  let gzip_command = s:get_gzip_command(tarfile)
-
   let curlast= line("$")
   if tarfile =~# '\.\(gz\|tgz\)$'
+    let gzip_command = s:get_gzip_command(tarfile)
 "   call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
    exe "sil! r! " . gzip_command . " -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
   elseif tarfile =~# '\.lrp'
 "   call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ")
-   exe "sil! r! cat -- ".shellescape(tarfile,1)."|" . gzip_command . " -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - "
+   exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - "
   elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$'
 "   call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
    exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
@@ -291,17 +290,16 @@ fun! tar#Read(fname,mode)
    let tar_secure= " "
   endif
 
-  let gzip_command = s:get_gzip_command(tarfile)
-
   if tarfile =~# '\.bz2$'
 "   call Decho("7: exe silent r! bzip2 -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp)
    exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
   elseif tarfile =~# '\.\(gz\|tgz\)$'
+    let gzip_command = s:get_gzip_command(tarfile)
 "   call Decho("5: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.shellescape(fname,1))
    exe "sil! r! " . gzip_command . " -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
   elseif tarfile =~# '\.lrp$'
 "   call Decho("6: exe silent r! cat ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp)
-   exe "sil! r! cat -- ".shellescape(tarfile,1)." | " . gzip_command . " -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
+   exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
   elseif tarfile =~# '\.lzma$'
 "   call Decho("7: exe silent r! lzma -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp)
    exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
@@ -589,8 +587,9 @@ fun! tar#Vimuntar(...)
 
   " if necessary, decompress the tarball; then, extract it
   if tartail =~ '\.tgz'
-   if executable("bzip2")
-    silent exe "!bzip2 -d ".shellescape(tartail)
+   let gzip_command = s:get_gzip_command(tarfile)
+   if executable(gzip_command)
+    silent exe "!" . gzip_command . " -d ".shellescape(tartail)
    elseif executable("gunzip")
     silent exe "!gunzip ".shellescape(tartail)
    elseif executable("gzip")
@@ -630,11 +629,24 @@ fun! tar#Vimuntar(...)
 endfun
 
 func s:get_gzip_command(file)
-  if a:file =~# 'z$' && executable('bzip2')
-    " Some .tgz files are actually compressed with bzip2.  Since bzip2 can
-    " handle the format from gzip, use it if the command exists.
+  " Try using the "file" command to get the actual compression type, since
+  " there is no standard way for the naming: ".tgz", ".tbz", ".txz", etc.
+  " If the "file" command doesn't work fall back to just using the file name.
+  if a:file =~# 'z$'
+    let filetype = system('file ' . a:file)
+    if filetype =~ 'bzip2 compressed' && executable('bzip2')
+      return 'bzip2'
+    endif
+    if filetype =~ 'XZ compressed' && executable('xz')
+      return 'xz'
+    endif
+  endif
+  if a:file =~# 'bz2$'
     return 'bzip2'
   endif
+  if a:file =~# 'xz$'
+    return 'xz'
+  endif
   return 'gzip'
 endfunc
 
--- a/src/version.c
+++ b/src/version.c
@@ -795,6 +795,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    352,
+/**/
     351,
 /**/
     350,