Mercurial > vim
annotate runtime/autoload/zip.vim @ 33482:39b2e200c4d7 v9.0.1992
patch 9.0.1992: [security] segfault in exmode
Commit: https://github.com/vim/vim/commit/20d161ace307e28690229b68584f2d84556f8960
Author: Christian Brabandt <cb@256bit.org>
Date: Thu Oct 5 22:08:30 2023 +0200
patch 9.0.1992: [security] segfault in exmode
Problem: segfault in exmode when redrawing
Solution: skip gui_scroll when exmode_active
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 05 Oct 2023 22:15:03 +0200 |
parents | 8bc48ca90534 |
children | bd3ee5abdd7a |
rev | line source |
---|---|
530 | 1 " zip.vim: Handles browsing zipfiles |
2 " AUTOLOAD PORTION | |
32294 | 3 " Date: Mar 12, 2023 |
4 " Version: 33 | |
19099 | 5 " Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
1121 | 6 " License: Vim License (see vim's :help license) |
19099 | 7 " Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1 |
530 | 8 " Permission is hereby granted to use and distribute this code, |
9 " with or without modifications, provided that this copyright | |
10 " notice is copied with it. Like anything else that's free, | |
1621 | 11 " zip.vim and zipPlugin.vim are provided *as is* and comes with |
12 " no warranty of any kind, either expressed or implied. By using | |
13 " this plugin, you agree that in no event will the copyright | |
530 | 14 " holder be liable for any damages resulting from the use |
15 " of this software. | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
16 "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
530 | 17 |
18 " --------------------------------------------------------------------- | |
1121 | 19 " Load Once: {{{1 |
2152 | 20 if &cp || exists("g:loaded_zip") |
21 finish | |
22 endif | |
32294 | 23 let g:loaded_zip= "v33" |
2152 | 24 if v:version < 702 |
25 echohl WarningMsg | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
26 echo "***warning*** this version of zip needs vim 7.2 or later" |
2152 | 27 echohl Normal |
28 finish | |
29 endif | |
530 | 30 let s:keepcpo= &cpo |
31 set cpo&vim | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
32 "DechoTabOn |
530 | 33 |
798 | 34 let s:zipfile_escape = ' ?&;\' |
1121 | 35 let s:ERROR = 2 |
36 let s:WARNING = 1 | |
37 let s:NOTE = 0 | |
38 | |
39 " --------------------------------------------------------------------- | |
40 " Global Values: {{{1 | |
41 if !exists("g:zip_shq") | |
1621 | 42 if &shq != "" |
43 let g:zip_shq= &shq | |
44 elseif has("unix") | |
1121 | 45 let g:zip_shq= "'" |
46 else | |
47 let g:zip_shq= '"' | |
48 endif | |
49 endif | |
1214 | 50 if !exists("g:zip_zipcmd") |
51 let g:zip_zipcmd= "zip" | |
52 endif | |
53 if !exists("g:zip_unzipcmd") | |
54 let g:zip_unzipcmd= "unzip" | |
55 endif | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
56 if !exists("g:zip_extractcmd") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
57 let g:zip_extractcmd= g:zip_unzipcmd |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
58 endif |
530 | 59 |
33196
8bc48ca90534
runtime(ftplugin): allow to exec if curdir is in PATH
Christian Brabandt <cb@256bit.org>
parents:
33096
diff
changeset
|
60 let s:tmp_cwd = getcwd() |
8bc48ca90534
runtime(ftplugin): allow to exec if curdir is in PATH
Christian Brabandt <cb@256bit.org>
parents:
33096
diff
changeset
|
61 if (fnamemodify(exepath(g:zip_unzipcmd), ":p:h") ==# getcwd() |
8bc48ca90534
runtime(ftplugin): allow to exec if curdir is in PATH
Christian Brabandt <cb@256bit.org>
parents:
33096
diff
changeset
|
62 \ && (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) == -1 || s:tmp_cwd == '.')) |
8bc48ca90534
runtime(ftplugin): allow to exec if curdir is in PATH
Christian Brabandt <cb@256bit.org>
parents:
33096
diff
changeset
|
63 unlet s:tmp_cwd |
33096
828bcb1a37e7
patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents:
32294
diff
changeset
|
64 echoerr "Warning: NOT executing " .. g:zip_unzipcmd .. " from current directory!" |
828bcb1a37e7
patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents:
32294
diff
changeset
|
65 finish |
828bcb1a37e7
patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents:
32294
diff
changeset
|
66 endif |
33196
8bc48ca90534
runtime(ftplugin): allow to exec if curdir is in PATH
Christian Brabandt <cb@256bit.org>
parents:
33096
diff
changeset
|
67 unlet s:tmp_cwd |
8bc48ca90534
runtime(ftplugin): allow to exec if curdir is in PATH
Christian Brabandt <cb@256bit.org>
parents:
33096
diff
changeset
|
68 |
530 | 69 " ---------------- |
70 " Functions: {{{1 | |
71 " ---------------- | |
72 | |
73 " --------------------------------------------------------------------- | |
74 " zip#Browse: {{{2 | |
75 fun! zip#Browse(zipfile) | |
76 " call Dfunc("zip#Browse(zipfile<".a:zipfile.">)") | |
22723 | 77 " sanity check: insure that the zipfile has "PK" as its first two letters |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
78 " (zipped files have a leading PK as a "magic cookie") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
79 if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK' |
19099 | 80 exe "noswapfile noautocmd noswapfile e ".fnameescape(a:zipfile) |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
81 " call Dret("zip#Browse : not a zipfile<".a:zipfile.">") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
82 return |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
83 " else " Decho |
19116 | 84 " call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - it's a zip file") |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
85 endif |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
86 |
568 | 87 let repkeep= &report |
88 set report=10 | |
530 | 89 |
90 " sanity checks | |
1698 | 91 if !exists("*fnameescape") |
92 if &verbose > 1 | |
25773 | 93 echoerr "the zip plugin is not available (your vim doesn't support fnameescape())" |
1698 | 94 endif |
95 return | |
96 endif | |
1214 | 97 if !executable(g:zip_unzipcmd) |
1121 | 98 redraw! |
530 | 99 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" |
1121 | 100 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 101 let &report= repkeep |
530 | 102 " call Dret("zip#Browse") |
103 return | |
104 endif | |
105 if !filereadable(a:zipfile) | |
557 | 106 if a:zipfile !~# '^\a\+://' |
19116 | 107 " if it's an url, don't complain, let url-handlers such as vim do its thing |
1121 | 108 redraw! |
557 | 109 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None |
1121 | 110 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 111 endif |
568 | 112 let &report= repkeep |
557 | 113 " call Dret("zip#Browse : file<".a:zipfile."> not readable") |
530 | 114 return |
115 endif | |
798 | 116 " call Decho("passed sanity checks") |
530 | 117 if &ma != 1 |
118 set ma | |
119 endif | |
1214 | 120 let b:zipfile= a:zipfile |
530 | 121 |
122 setlocal noswapfile | |
123 setlocal buftype=nofile | |
124 setlocal bufhidden=hide | |
125 setlocal nobuflisted | |
126 setlocal nowrap | |
26148 | 127 |
128 " Oct 12, 2021: need to re-use Bram's syntax/tar.vim. | |
129 " Setting the filetype to zip doesn't do anything (currently), | |
130 " but it is perhaps less confusing to curious perusers who do | |
131 " a :echo &ft | |
132 setf zip | |
133 run! syntax/tar.vim | |
530 | 134 |
135 " give header | |
2908 | 136 call append(0, ['" zip.vim version '.g:loaded_zip, |
3281 | 137 \ '" Browsing zipfile '.a:zipfile, |
138 \ '" Select a file with cursor and press ENTER']) | |
2908 | 139 keepj $ |
530 | 140 |
1698 | 141 " call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1)) |
3281 | 142 exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1) |
857 | 143 if v:shell_error != 0 |
1121 | 144 redraw! |
1668 | 145 echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None |
1121 | 146 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
2908 | 147 keepj sil! %d |
857 | 148 let eikeep= &ei |
149 set ei=BufReadCmd,FileReadCmd | |
2908 | 150 exe "keepj r ".fnameescape(a:zipfile) |
857 | 151 let &ei= eikeep |
2908 | 152 keepj 1d |
857 | 153 " call Dret("zip#Browse") |
154 return | |
155 endif | |
530 | 156 |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
157 " Maps associated with zip plugin |
530 | 158 setlocal noma nomod ro |
19099 | 159 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr> |
160 noremap <silent> <buffer> x :call zip#Extract()<cr> | |
161 if &mouse != "" | |
162 noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>ZipBrowseSelect()<cr> | |
163 endif | |
530 | 164 |
568 | 165 let &report= repkeep |
530 | 166 " call Dret("zip#Browse") |
167 endfun | |
168 | |
169 " --------------------------------------------------------------------- | |
170 " ZipBrowseSelect: {{{2 | |
171 fun! s:ZipBrowseSelect() | |
32294 | 172 " call Dfunc("ZipBrowseSelect() zipfile<".((exists("b:zipfile"))? b:zipfile : "n/a")."> curfile<".expand("%").">") |
568 | 173 let repkeep= &report |
174 set report=10 | |
530 | 175 let fname= getline(".") |
32294 | 176 if !exists("b:zipfile") |
177 " call Dret("ZipBrowseSelect : b:zipfile doesn't exist!") | |
178 return | |
179 endif | |
530 | 180 |
181 " sanity check | |
182 if fname =~ '^"' | |
568 | 183 let &report= repkeep |
530 | 184 " call Dret("ZipBrowseSelect") |
185 return | |
186 endif | |
187 if fname =~ '/$' | |
1121 | 188 redraw! |
530 | 189 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None |
1121 | 190 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 191 let &report= repkeep |
530 | 192 " call Dret("ZipBrowseSelect") |
193 return | |
194 endif | |
195 | |
196 " call Decho("fname<".fname.">") | |
197 | |
198 " get zipfile to the new-window | |
1214 | 199 let zipfile = b:zipfile |
19099 | 200 let curfile = expand("%") |
798 | 201 " call Decho("zipfile<".zipfile.">") |
202 " call Decho("curfile<".curfile.">") | |
530 | 203 |
19099 | 204 noswapfile new |
1621 | 205 if !exists("g:zip_nomax") || g:zip_nomax == 0 |
206 wincmd _ | |
207 endif | |
557 | 208 let s:zipfile_{winnr()}= curfile |
26148 | 209 " call Decho("exe e ".fnameescape("zipfile://".zipfile.'::'.fname)) |
210 exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname) | |
530 | 211 filetype detect |
212 | |
568 | 213 let &report= repkeep |
557 | 214 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
530 | 215 endfun |
216 | |
217 " --------------------------------------------------------------------- | |
218 " zip#Read: {{{2 | |
219 fun! zip#Read(fname,mode) | |
220 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")") | |
568 | 221 let repkeep= &report |
222 set report=10 | |
223 | |
857 | 224 if has("unix") |
26148 | 225 let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') |
226 let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','') | |
857 | 227 else |
26148 | 228 let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','') |
229 let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','') | |
4339 | 230 let fname = substitute(fname, '[', '[[]', 'g') |
857 | 231 endif |
232 " call Decho("zipfile<".zipfile.">") | |
233 " call Decho("fname <".fname.">") | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
234 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
235 if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
236 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
237 echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
238 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
239 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
240 " call Dret("zip#Write") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
241 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
242 endif |
530 | 243 |
4339 | 244 " the following code does much the same thing as |
245 " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1) | |
26148 | 246 " but allows zipfile://... entries in quickfix lists |
4339 | 247 let temp = tempname() |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
248 " call Decho("using temp file<".temp.">") |
4339 | 249 let fn = expand('%:p') |
250 exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp | |
251 " call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp) | |
252 sil exe 'keepalt file '.temp | |
253 sil keepj e! | |
254 sil exe 'keepalt file '.fnameescape(fn) | |
255 call delete(temp) | |
256 | |
2908 | 257 filetype detect |
530 | 258 |
259 " cleanup | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
260 " keepj 0d " used to be needed for the ...r! ... method |
530 | 261 set nomod |
262 | |
568 | 263 let &report= repkeep |
530 | 264 " call Dret("zip#Read") |
265 endfun | |
266 | |
267 " --------------------------------------------------------------------- | |
268 " zip#Write: {{{2 | |
269 fun! zip#Write(fname) | |
819 | 270 " call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
568 | 271 let repkeep= &report |
272 set report=10 | |
530 | 273 |
274 " sanity checks | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
275 if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) |
1121 | 276 redraw! |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
277 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None |
1121 | 278 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 279 let &report= repkeep |
530 | 280 " call Dret("zip#Write") |
281 return | |
282 endif | |
283 if !exists("*mkdir") | |
1121 | 284 redraw! |
530 | 285 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None |
1121 | 286 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 287 let &report= repkeep |
530 | 288 " call Dret("zip#Write") |
289 return | |
290 endif | |
291 | |
292 let curdir= getcwd() | |
293 let tmpdir= tempname() | |
294 " call Decho("orig tempname<".tmpdir.">") | |
295 if tmpdir =~ '\.' | |
296 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
297 endif | |
298 " call Decho("tmpdir<".tmpdir.">") | |
299 call mkdir(tmpdir,"p") | |
300 | |
301 " attempt to change to the indicated directory | |
1121 | 302 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") |
568 | 303 let &report= repkeep |
530 | 304 " call Dret("zip#Write") |
305 return | |
1121 | 306 endif |
530 | 307 " call Decho("current directory now: ".getcwd()) |
308 | |
309 " place temporary files under .../_ZIPVIM_/ | |
310 if isdirectory("_ZIPVIM_") | |
311 call s:Rmdir("_ZIPVIM_") | |
312 endif | |
313 call mkdir("_ZIPVIM_") | |
314 cd _ZIPVIM_ | |
315 " call Decho("current directory now: ".getcwd()) | |
316 | |
857 | 317 if has("unix") |
26148 | 318 let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') |
319 let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','') | |
857 | 320 else |
26148 | 321 let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','') |
322 let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','') | |
857 | 323 endif |
324 " call Decho("zipfile<".zipfile.">") | |
325 " call Decho("fname <".fname.">") | |
623 | 326 |
327 if fname =~ '/' | |
328 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
4339 | 329 if has("win32unix") && executable("cygpath") |
1668 | 330 let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e') |
623 | 331 endif |
819 | 332 " call Decho("mkdir(dirpath<".dirpath.">,p)") |
623 | 333 call mkdir(dirpath,"p") |
334 endif | |
530 | 335 if zipfile !~ '/' |
336 let zipfile= curdir.'/'.zipfile | |
337 endif | |
338 " call Decho("zipfile<".zipfile."> fname<".fname.">") | |
339 | |
1668 | 340 exe "w! ".fnameescape(fname) |
4339 | 341 if has("win32unix") && executable("cygpath") |
1668 | 342 let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e') |
530 | 343 endif |
344 | |
1121 | 345 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
346 let fname = substitute(fname, '[', '[[]', 'g') | |
347 endif | |
348 | |
1698 | 349 " call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) |
350 call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) | |
530 | 351 if v:shell_error != 0 |
1121 | 352 redraw! |
530 | 353 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None |
1121 | 354 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 355 |
356 elseif s:zipfile_{winnr()} =~ '^\a\+://' | |
357 " support writing zipfiles across a network | |
358 let netzipfile= s:zipfile_{winnr()} | |
1121 | 359 " call Decho("handle writing <".zipfile."> across network as <".netzipfile.">") |
557 | 360 1split|enew |
361 let binkeep= &binary | |
362 let eikeep = &ei | |
363 set binary ei=all | |
19099 | 364 exe "noswapfile e! ".fnameescape(zipfile) |
557 | 365 call netrw#NetWrite(netzipfile) |
366 let &ei = eikeep | |
367 let &binary = binkeep | |
368 q! | |
369 unlet s:zipfile_{winnr()} | |
530 | 370 endif |
371 | |
372 " cleanup and restore current directory | |
373 cd .. | |
374 call s:Rmdir("_ZIPVIM_") | |
1121 | 375 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!") |
376 call s:Rmdir(tmpdir) | |
530 | 377 setlocal nomod |
378 | |
568 | 379 let &report= repkeep |
530 | 380 " call Dret("zip#Write") |
381 endfun | |
382 | |
383 " --------------------------------------------------------------------- | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
384 " zip#Extract: extract a file from a zip archive {{{2 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
385 fun! zip#Extract() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
386 " call Dfunc("zip#Extract()") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
387 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
388 let repkeep= &report |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
389 set report=10 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
390 let fname= getline(".") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
391 " call Decho("fname<".fname.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
392 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
393 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
394 if fname =~ '^"' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
395 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
396 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
397 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
398 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
399 if fname =~ '/$' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
400 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
401 echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
402 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
403 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
404 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
405 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
406 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
407 " extract the file mentioned under the cursor |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
408 " call Decho("system(".g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell).")") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
409 call system(g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell)) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
410 " call Decho("zipfile<".b:zipfile.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
411 if v:shell_error != 0 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
412 echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
413 elseif !filereadable(fname) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
414 echohl Error | echo "***error*** attempted to extract ".fname." but it doesn't appear to be present!" |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
415 else |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
416 echo "***note*** successfully extracted ".fname |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
417 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
418 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
419 " restore option |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
420 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
421 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
422 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
423 endfun |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
424 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
425 " --------------------------------------------------------------------- |
1668 | 426 " s:Escape: {{{2 |
427 fun! s:Escape(fname,isfilt) | |
428 " call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")") | |
429 if exists("*shellescape") | |
430 if a:isfilt | |
431 let qnameq= shellescape(a:fname,1) | |
432 else | |
433 let qnameq= shellescape(a:fname) | |
434 endif | |
1621 | 435 else |
436 let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq | |
437 endif | |
438 " call Dret("QuoteFileDir <".qnameq.">") | |
439 return qnameq | |
1121 | 440 endfun |
441 | |
442 " --------------------------------------------------------------------- | |
443 " ChgDir: {{{2 | |
444 fun! s:ChgDir(newdir,errlvl,errmsg) | |
445 " call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)") | |
446 | |
447 try | |
1698 | 448 exe "cd ".fnameescape(a:newdir) |
1121 | 449 catch /^Vim\%((\a\+)\)\=:E344/ |
450 redraw! | |
451 if a:errlvl == s:NOTE | |
452 echo "***note*** ".a:errmsg | |
453 elseif a:errlvl == s:WARNING | |
454 echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE | |
455 elseif a:errlvl == s:ERROR | |
456 echohl Error | echo "***error*** ".a:errmsg | echohl NONE | |
457 endif | |
458 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
459 " call Dret("ChgDir 1") | |
460 return 1 | |
461 endtry | |
462 | |
463 " call Dret("ChgDir 0") | |
464 return 0 | |
465 endfun | |
466 | |
467 " --------------------------------------------------------------------- | |
1668 | 468 " s:Rmdir: {{{2 |
530 | 469 fun! s:Rmdir(fname) |
470 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
1121 | 471 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
1668 | 472 call system("rmdir /S/Q ".s:Escape(a:fname,0)) |
1121 | 473 else |
1668 | 474 call system("/bin/rm -rf ".s:Escape(a:fname,0)) |
530 | 475 endif |
476 " call Dret("Rmdir") | |
477 endfun | |
478 | |
479 " ------------------------------------------------------------------------ | |
480 " Modelines And Restoration: {{{1 | |
481 let &cpo= s:keepcpo | |
482 unlet s:keepcpo | |
1214 | 483 " vim:ts=8 fdm=marker |