mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	vim-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.
d4a1aabe37
			
			
This commit is contained in:
		@@ -153,15 +153,14 @@ fun! tar#Browse(tarfile)
 | 
				
			|||||||
   let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e')
 | 
					   let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e')
 | 
				
			||||||
  endif
 | 
					  endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let gzip_command = s:get_gzip_command(tarfile)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  let curlast= line("$")
 | 
					  let curlast= line("$")
 | 
				
			||||||
  if tarfile =~# '\.\(gz\|tgz\)$'
 | 
					  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." - ")
 | 
					"   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." - "
 | 
					   exe "sil! r! " . gzip_command . " -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
 | 
				
			||||||
  elseif tarfile =~# '\.lrp'
 | 
					  elseif tarfile =~# '\.lrp'
 | 
				
			||||||
"   call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ")
 | 
					"   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\)$'
 | 
					  elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$'
 | 
				
			||||||
"   call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
 | 
					"   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." - "
 | 
					   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= " "
 | 
					   let tar_secure= " "
 | 
				
			||||||
  endif
 | 
					  endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let gzip_command = s:get_gzip_command(tarfile)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if tarfile =~# '\.bz2$'
 | 
					  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)
 | 
					"   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
 | 
					   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\)$'
 | 
					  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))
 | 
					"   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
 | 
					   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$'
 | 
					  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)
 | 
					"   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$'
 | 
					  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)
 | 
					"   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
 | 
					   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 necessary, decompress the tarball; then, extract it
 | 
				
			||||||
  if tartail =~ '\.tgz'
 | 
					  if tartail =~ '\.tgz'
 | 
				
			||||||
   if executable("bzip2")
 | 
					   let gzip_command = s:get_gzip_command(tarfile)
 | 
				
			||||||
    silent exe "!bzip2 -d ".shellescape(tartail)
 | 
					   if executable(gzip_command)
 | 
				
			||||||
 | 
					    silent exe "!" . gzip_command . " -d ".shellescape(tartail)
 | 
				
			||||||
   elseif executable("gunzip")
 | 
					   elseif executable("gunzip")
 | 
				
			||||||
    silent exe "!gunzip ".shellescape(tartail)
 | 
					    silent exe "!gunzip ".shellescape(tartail)
 | 
				
			||||||
   elseif executable("gzip")
 | 
					   elseif executable("gzip")
 | 
				
			||||||
@@ -630,11 +629,24 @@ fun! tar#Vimuntar(...)
 | 
				
			|||||||
endfun
 | 
					endfun
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func s:get_gzip_command(file)
 | 
					func s:get_gzip_command(file)
 | 
				
			||||||
  if a:file =~# 'z$' && executable('bzip2')
 | 
					  " Try using the "file" command to get the actual compression type, since
 | 
				
			||||||
    " Some .tgz files are actually compressed with bzip2.  Since bzip2 can
 | 
					  " there is no standard way for the naming: ".tgz", ".tbz", ".txz", etc.
 | 
				
			||||||
    " handle the format from gzip, use it if the command exists.
 | 
					  " 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'
 | 
					    return 'bzip2'
 | 
				
			||||||
  endif
 | 
					  endif
 | 
				
			||||||
 | 
					  if a:file =~# 'xz$'
 | 
				
			||||||
 | 
					    return 'xz'
 | 
				
			||||||
 | 
					  endif
 | 
				
			||||||
  return 'gzip'
 | 
					  return 'gzip'
 | 
				
			||||||
endfunc
 | 
					endfunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user