annotate runtime/autoload/gzip.vim @ 36533:90545c76016e draft default tip

runtime(tar): Update tar.vim to support permissions Commit: https://github.com/vim/vim/commit/129a8446d23cd9cb4445fcfea259cba5e0487d29 Author: Lennart00 <73488709+Lennart00@users.noreply.github.com> Date: Mon Nov 11 22:39:30 2024 +0100 runtime(tar): Update tar.vim to support permissions These changes enable tar.vim to keep permissions of files that were edited intact instead of replacing them with the default permissions. The major change for this is switching from "tar -OPxf", which reads out the contents of the selected file from an tar archive to stdout to "tar -pPxf" which extracts the selected file to the current directory with permissions intact This requirs the temporary directory to be created earlier. closes: #7379 Signed-off-by: Lennart00 <73488709+Lennart00@users.noreply.github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Mon, 11 Nov 2024 22:45:02 +0100
parents bd3ee5abdd7a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
1 " Vim autoload file for editing compressed files.
32770
4027cefc2aab Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents: 10244
diff changeset
2 " Maintainer: The Vim Project <https://github.com/vim/vim>
4027cefc2aab Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents: 10244
diff changeset
3 " Last Change: 2023 Aug 10
4027cefc2aab Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents: 10244
diff changeset
4 " Former Maintainer: Bram Moolenaar <Bram@vim.org>
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
5
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
6 " These functions are used by the gzip plugin.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
7
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
8 " Function to check that executing "cmd [-f]" works.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
9 " The result is cached in s:have_"cmd" for speed.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
10 fun s:check(cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
11 let name = substitute(a:cmd, '\(\S*\).*', '\1', '')
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
12 if !exists("s:have_" . name)
33096
828bcb1a37e7 patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents: 32770
diff changeset
13 " safety check, don't execute anything from the current directory
33716
bd3ee5abdd7a runtime(dist): centralize safe executable check and add vim library (#13413)
Christian Brabandt <cb@256bit.org>
parents: 33196
diff changeset
14 let f = dist#vim#IsSafeExecutable('gzip', name)
33096
828bcb1a37e7 patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents: 32770
diff changeset
15 if !f
828bcb1a37e7 patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents: 32770
diff changeset
16 echoerr "Warning: NOT executing " .. name .. " from current directory!"
828bcb1a37e7 patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents: 32770
diff changeset
17 endif
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
18 let e = executable(name)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
19 if e < 0
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
20 let r = system(name . " --version")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
21 let e = (r !~ "not found" && r != "")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
22 endif
33096
828bcb1a37e7 patch 9.0.1833: [security] runtime file fixes
Christian Brabandt <cb@256bit.org>
parents: 32770
diff changeset
23 exe "let s:have_" . name . "=" . (e && f)
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
24 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
25 exe "return s:have_" . name
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
26 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
27
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
28 " Set b:gzip_comp_arg to the gzip argument to be used for compression, based on
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
29 " the flags in the compressed file.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
30 " The only compression methods that can be detected are max speed (-1) and max
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
31 " compression (-9).
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
32 fun s:set_compression(line)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
33 " get the Compression Method
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
34 let l:cm = char2nr(a:line[2])
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
35 " if it's 8 (DEFLATE), we can check for the compression level
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
36 if l:cm == 8
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
37 " get the eXtra FLags
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
38 let l:xfl = char2nr(a:line[8])
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
39 " max compression
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
40 if l:xfl == 2
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
41 let b:gzip_comp_arg = "-9"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
42 " min compression
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
43 elseif l:xfl == 4
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
44 let b:gzip_comp_arg = "-1"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
45 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
46 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
47 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
48
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
49
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
50 " After reading compressed file: Uncompress text in buffer with "cmd"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
51 fun gzip#read(cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
52 " don't do anything if the cmd is not supported
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
53 if !s:check(a:cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
54 return
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
55 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
56
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
57 " for gzip check current compression level and set b:gzip_comp_arg.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
58 silent! unlet b:gzip_comp_arg
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
59 if a:cmd[0] == 'g'
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
60 call s:set_compression(getline(1))
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
61 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
62
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
63 " make 'patchmode' empty, we don't want a copy of the written file
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
64 let pm_save = &pm
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
65 set pm=
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
66 " remove 'a' and 'A' from 'cpo' to avoid the alternate file changes
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
67 let cpo_save = &cpo
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
68 set cpo-=a cpo-=A
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
69 " set 'modifiable'
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
70 let ma_save = &ma
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
71 setlocal ma
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
72 " set 'write'
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
73 let write_save = &write
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
74 set write
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
75 " Reset 'foldenable', otherwise line numbers get adjusted.
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
76 if has("folding")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
77 let fen_save = &fen
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
78 setlocal nofen
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
79 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
80
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
81 " when filtering the whole buffer, it will become empty
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
82 let empty = line("'[") == 1 && line("']") == line("$")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
83 let tmp = tempname()
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
84 let tmpe = tmp . "." . expand("<afile>:e")
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
85 if exists('*fnameescape')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
86 let tmp_esc = fnameescape(tmp)
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
87 let tmpe_esc = fnameescape(tmpe)
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
88 else
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
89 let tmp_esc = escape(tmp, ' ')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
90 let tmpe_esc = escape(tmpe, ' ')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
91 endif
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
92 " write the just read lines to a temp file "'[,']w tmp.gz"
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
93 execute "silent '[,']w " . tmpe_esc
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
94 " uncompress the temp file: call system("gzip -dn tmp.gz")
985
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
95 call system(a:cmd . " " . s:escape(tmpe))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
96 if !filereadable(tmp)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
97 " uncompress didn't work! Keep the compressed file then.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
98 echoerr "Error: Could not read uncompressed file"
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
99 let ok = 0
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
100 else
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
101 let ok = 1
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
102 " delete the compressed lines; remember the line number
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
103 let l = line("'[") - 1
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
104 if exists(":lockmarks")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
105 lockmarks '[,']d _
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
106 else
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
107 '[,']d _
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
108 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
109 " read in the uncompressed lines "'[-1r tmp"
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
110 " Use ++edit if the buffer was empty, keep the 'ff' and 'fenc' options.
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
111 setlocal nobin
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
112 if exists(":lockmarks")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
113 if empty
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
114 execute "silent lockmarks " . l . "r ++edit " . tmp_esc
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
115 else
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
116 execute "silent lockmarks " . l . "r " . tmp_esc
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
117 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
118 else
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
119 execute "silent " . l . "r " . tmp_esc
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
120 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
121
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
122 " if buffer became empty, delete trailing blank line
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 446
diff changeset
123 if empty
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
124 silent $delete _
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
125 1
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 446
diff changeset
126 endif
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
127 " delete the temp file and the used buffers
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
128 call delete(tmp)
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
129 silent! exe "bwipe " . tmp_esc
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
130 silent! exe "bwipe " . tmpe_esc
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
131 endif
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
132 " Store the OK flag, so that we can use it when writing.
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
133 let b:uncompressOk = ok
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
134
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
135 " Restore saved option values.
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
136 let &pm = pm_save
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
137 let &cpo = cpo_save
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
138 let &l:ma = ma_save
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
139 let &write = write_save
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
140 if has("folding")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
141 let &l:fen = fen_save
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
142 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
143
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
144 " When uncompressed the whole buffer, do autocommands
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
145 if ok && empty
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
146 if exists('*fnameescape')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
147 let fname = fnameescape(expand("%:r"))
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
148 else
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
149 let fname = escape(expand("%:r"), " \t\n*?[{`$\\%#'\"|!<")
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
150 endif
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
151 if &verbose >= 8
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
152 execute "doau BufReadPost " . fname
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
153 else
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
154 execute "silent! doau BufReadPost " . fname
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
155 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
156 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
157 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
158
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
159 " After writing compressed file: Compress written file with "cmd"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
160 fun gzip#write(cmd)
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
161 if exists('b:uncompressOk') && !b:uncompressOk
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
162 echomsg "Not compressing file because uncompress failed; reset b:uncompressOk to compress anyway"
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
163 " don't do anything if the cmd is not supported
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
164 elseif s:check(a:cmd)
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
165 " Rename the file before compressing it.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
166 let nm = resolve(expand("<afile>"))
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
167 let nmt = s:tempname(nm)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
168 if rename(nm, nmt) == 0
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
169 if exists("b:gzip_comp_arg")
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
170 call system(a:cmd . " " . b:gzip_comp_arg . " -- " . s:escape(nmt))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
171 else
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
172 call system(a:cmd . " -- " . s:escape(nmt))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
173 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
174 call rename(nmt . "." . expand("<afile>:e"), nm)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
175 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
176 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
177 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
178
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
179 " Before appending to compressed file: Uncompress file with "cmd"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
180 fun gzip#appre(cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
181 " don't do anything if the cmd is not supported
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
182 if s:check(a:cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
183 let nm = expand("<afile>")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
184
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
185 " for gzip check current compression level and set b:gzip_comp_arg.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
186 silent! unlet b:gzip_comp_arg
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
187 if a:cmd[0] == 'g'
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
188 call s:set_compression(readfile(nm, "b", 1)[0])
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
189 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
190
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
191 " Rename to a weird name to avoid the risk of overwriting another file
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
192 let nmt = expand("<afile>:p:h") . "/X~=@l9q5"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
193 let nmte = nmt . "." . expand("<afile>:e")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
194 if rename(nm, nmte) == 0
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
195 if &patchmode != "" && getfsize(nm . &patchmode) == -1
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
196 " Create patchmode file by creating the decompressed file new
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
197 call system(a:cmd . " -c -- " . s:escape(nmte) . " > " . s:escape(nmt))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
198 call rename(nmte, nm . &patchmode)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
199 else
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
200 call system(a:cmd . " -- " . s:escape(nmte))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
201 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
202 call rename(nmt, nm)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
203 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
204 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
205 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
206
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
207 " find a file name for the file to be compressed. Use "name" without an
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
208 " extension if possible. Otherwise use a weird name to avoid overwriting an
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
209 " existing file.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
210 fun s:tempname(name)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
211 let fn = fnamemodify(a:name, ":r")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
212 if !filereadable(fn) && !isdirectory(fn)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
213 return fn
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
214 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
215 return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
216 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
217
985
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
218 fun s:escape(name)
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
219 " shellescape() was added by patch 7.0.111
1132
857a5e3e1d34 updated for version 7.1a
vimboss
parents: 985
diff changeset
220 if exists("*shellescape")
985
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
221 return shellescape(a:name)
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
222 endif
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
223 return "'" . a:name . "'"
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
224 endfun
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
225
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
226 " vim: set sw=2 :