]>
Commit | Line | Data |
---|---|---|
bb987377 ER |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.172 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.3.172 | |
11 | Problem: MS-Windows: rename() might delete the file if the name differs but | |
12 | it's actually the same file. | |
13 | Solution: Use the file handle to check if it's the same file. (Yukihiro | |
14 | Nakadaira) | |
15 | Files: src/if_cscope.c, src/fileio.c, src/os_win32.c, | |
16 | src/proto/os_win32.pro, src/vim.h | |
17 | ||
18 | ||
19 | *** ../vim-7.3.171/src/if_cscope.c 2011-03-03 15:01:25.000000000 +0100 | |
20 | --- src/if_cscope.c 2011-05-05 16:16:38.000000000 +0200 | |
21 | *************** | |
22 | *** 1412,1428 **** | |
23 | { | |
24 | short i, j; | |
25 | #ifndef UNIX | |
26 | - HANDLE hFile; | |
27 | BY_HANDLE_FILE_INFORMATION bhfi; | |
28 | ||
29 | - vim_memset(&bhfi, 0, sizeof(bhfi)); | |
30 | /* On windows 9x GetFileInformationByHandle doesn't work, so skip it */ | |
31 | if (!mch_windows95()) | |
32 | { | |
33 | ! hFile = CreateFile(fname, FILE_READ_ATTRIBUTES, 0, NULL, OPEN_EXISTING, | |
34 | ! FILE_ATTRIBUTE_NORMAL, NULL); | |
35 | ! if (hFile == INVALID_HANDLE_VALUE) | |
36 | { | |
37 | if (p_csverbose) | |
38 | { | |
39 | char *cant_msg = _("E625: cannot open cscope database: %s"); | |
40 | --- 1412,1426 ---- | |
41 | { | |
42 | short i, j; | |
43 | #ifndef UNIX | |
44 | BY_HANDLE_FILE_INFORMATION bhfi; | |
45 | ||
46 | /* On windows 9x GetFileInformationByHandle doesn't work, so skip it */ | |
47 | if (!mch_windows95()) | |
48 | { | |
49 | ! switch (win32_fileinfo(fname, &bhfi)) | |
50 | { | |
51 | + case FILEINFO_ENC_FAIL: /* enc_to_utf16() failed */ | |
52 | + case FILEINFO_READ_FAIL: /* CreateFile() failed */ | |
53 | if (p_csverbose) | |
54 | { | |
55 | char *cant_msg = _("E625: cannot open cscope database: %s"); | |
56 | *************** | |
57 | *** 1438,1452 **** | |
58 | (void)EMSG2(cant_msg, fname); | |
59 | } | |
60 | return -1; | |
61 | ! } | |
62 | ! if (!GetFileInformationByHandle(hFile, &bhfi)) | |
63 | ! { | |
64 | ! CloseHandle(hFile); | |
65 | if (p_csverbose) | |
66 | (void)EMSG(_("E626: cannot get cscope database information")); | |
67 | return -1; | |
68 | } | |
69 | - CloseHandle(hFile); | |
70 | } | |
71 | #endif | |
72 | ||
73 | --- 1436,1447 ---- | |
74 | (void)EMSG2(cant_msg, fname); | |
75 | } | |
76 | return -1; | |
77 | ! | |
78 | ! case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */ | |
79 | if (p_csverbose) | |
80 | (void)EMSG(_("E626: cannot get cscope database information")); | |
81 | return -1; | |
82 | } | |
83 | } | |
84 | #endif | |
85 | ||
86 | *** ../vim-7.3.171/src/fileio.c 2011-04-11 21:35:03.000000000 +0200 | |
87 | --- src/fileio.c 2011-05-05 16:22:22.000000000 +0200 | |
88 | *************** | |
89 | *** 6555,6560 **** | |
90 | --- 6555,6575 ---- | |
91 | use_tmp_file = TRUE; | |
92 | } | |
93 | #endif | |
94 | + #ifdef WIN3264 | |
95 | + { | |
96 | + BY_HANDLE_FILE_INFORMATION info1, info2; | |
97 | + | |
98 | + /* It's possible for the source and destination to be the same file. | |
99 | + * In that case go through a temp file name. This makes rename("foo", | |
100 | + * "./foo") a no-op (in a complicated way). */ | |
101 | + if (win32_fileinfo(from, &info1) == FILEINFO_OK | |
102 | + && win32_fileinfo(to, &info2) == FILEINFO_OK | |
103 | + && info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber | |
104 | + && info1.nFileIndexHigh == info2.nFileIndexHigh | |
105 | + && info1.nFileIndexLow == info2.nFileIndexLow) | |
106 | + use_tmp_file = TRUE; | |
107 | + } | |
108 | + #endif | |
109 | ||
110 | #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME) | |
111 | if (use_tmp_file) | |
112 | *** ../vim-7.3.171/src/os_win32.c 2011-02-01 13:48:47.000000000 +0100 | |
113 | --- src/os_win32.c 2011-05-05 16:24:17.000000000 +0200 | |
114 | *************** | |
115 | *** 2645,2669 **** | |
116 | int | |
117 | mch_is_linked(char_u *fname) | |
118 | { | |
119 | HANDLE hFile; | |
120 | ! int res = 0; | |
121 | ! BY_HANDLE_FILE_INFORMATION inf; | |
122 | #ifdef FEAT_MBYTE | |
123 | WCHAR *wn = NULL; | |
124 | ||
125 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
126 | wn = enc_to_utf16(fname, NULL); | |
127 | if (wn != NULL) | |
128 | { | |
129 | hFile = CreateFileW(wn, /* file name */ | |
130 | GENERIC_READ, /* access mode */ | |
131 | ! 0, /* share mode */ | |
132 | NULL, /* security descriptor */ | |
133 | OPEN_EXISTING, /* creation disposition */ | |
134 | ! 0, /* file attributes */ | |
135 | NULL); /* handle to template file */ | |
136 | if (hFile == INVALID_HANDLE_VALUE | |
137 | ! && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) | |
138 | { | |
139 | /* Retry with non-wide function (for Windows 98). */ | |
140 | vim_free(wn); | |
141 | --- 2645,2688 ---- | |
142 | int | |
143 | mch_is_linked(char_u *fname) | |
144 | { | |
145 | + BY_HANDLE_FILE_INFORMATION info; | |
146 | + | |
147 | + return win32_fileinfo(fname, &info) == FILEINFO_OK | |
148 | + && info.nNumberOfLinks > 1; | |
149 | + } | |
150 | + | |
151 | + /* | |
152 | + * Get the by-handle-file-information for "fname". | |
153 | + * Returns FILEINFO_OK when OK. | |
154 | + * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
155 | + * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
156 | + * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
157 | + */ | |
158 | + int | |
159 | + win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
160 | + { | |
161 | HANDLE hFile; | |
162 | ! int res = FILEINFO_READ_FAIL; | |
163 | #ifdef FEAT_MBYTE | |
164 | WCHAR *wn = NULL; | |
165 | ||
166 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
167 | + { | |
168 | wn = enc_to_utf16(fname, NULL); | |
169 | + if (wn == NULL) | |
170 | + res = FILEINFO_ENC_FAIL; | |
171 | + } | |
172 | if (wn != NULL) | |
173 | { | |
174 | hFile = CreateFileW(wn, /* file name */ | |
175 | GENERIC_READ, /* access mode */ | |
176 | ! FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ | |
177 | NULL, /* security descriptor */ | |
178 | OPEN_EXISTING, /* creation disposition */ | |
179 | ! FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ | |
180 | NULL); /* handle to template file */ | |
181 | if (hFile == INVALID_HANDLE_VALUE | |
182 | ! && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) | |
183 | { | |
184 | /* Retry with non-wide function (for Windows 98). */ | |
185 | vim_free(wn); | |
186 | *************** | |
187 | *** 2674,2690 **** | |
188 | #endif | |
189 | hFile = CreateFile(fname, /* file name */ | |
190 | GENERIC_READ, /* access mode */ | |
191 | ! 0, /* share mode */ | |
192 | NULL, /* security descriptor */ | |
193 | OPEN_EXISTING, /* creation disposition */ | |
194 | ! 0, /* file attributes */ | |
195 | NULL); /* handle to template file */ | |
196 | ||
197 | if (hFile != INVALID_HANDLE_VALUE) | |
198 | { | |
199 | ! if (GetFileInformationByHandle(hFile, &inf) != 0 | |
200 | ! && inf.nNumberOfLinks > 1) | |
201 | ! res = 1; | |
202 | CloseHandle(hFile); | |
203 | } | |
204 | ||
205 | --- 2693,2710 ---- | |
206 | #endif | |
207 | hFile = CreateFile(fname, /* file name */ | |
208 | GENERIC_READ, /* access mode */ | |
209 | ! FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ | |
210 | NULL, /* security descriptor */ | |
211 | OPEN_EXISTING, /* creation disposition */ | |
212 | ! FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ | |
213 | NULL); /* handle to template file */ | |
214 | ||
215 | if (hFile != INVALID_HANDLE_VALUE) | |
216 | { | |
217 | ! if (GetFileInformationByHandle(hFile, info) != 0) | |
218 | ! res = FILEINFO_OK; | |
219 | ! else | |
220 | ! res = FILEINFO_INFO_FAIL; | |
221 | CloseHandle(hFile); | |
222 | } | |
223 | ||
224 | *** ../vim-7.3.171/src/proto/os_win32.pro 2010-10-23 14:02:48.000000000 +0200 | |
225 | --- src/proto/os_win32.pro 2011-05-05 16:17:42.000000000 +0200 | |
226 | *************** | |
227 | *** 21,26 **** | |
228 | --- 21,27 ---- | |
229 | void mch_hide __ARGS((char_u *name)); | |
230 | int mch_isdir __ARGS((char_u *name)); | |
231 | int mch_is_linked __ARGS((char_u *fname)); | |
232 | + int win32_fileinfo __ARGS((char_u *name, BY_HANDLE_FILE_INFORMATION *lpFileInfo)); | |
233 | int mch_writable __ARGS((char_u *name)); | |
234 | int mch_can_exe __ARGS((char_u *name)); | |
235 | int mch_nodetype __ARGS((char_u *name)); | |
236 | *** ../vim-7.3.171/src/vim.h 2011-04-11 21:35:03.000000000 +0200 | |
237 | --- src/vim.h 2011-05-05 16:16:57.000000000 +0200 | |
238 | *************** | |
239 | *** 2217,2220 **** | |
240 | --- 2217,2226 ---- | |
241 | #define KEYLEN_PART_MAP -2 /* keylen value for incomplete mapping */ | |
242 | #define KEYLEN_REMOVED 9999 /* keylen value for removed sequence */ | |
243 | ||
244 | + /* Return values from win32_fileinfo(). */ | |
245 | + #define FILEINFO_OK 0 | |
246 | + #define FILEINFO_ENC_FAIL 1 /* enc_to_utf16() failed */ | |
247 | + #define FILEINFO_READ_FAIL 2 /* CreateFile() failed */ | |
248 | + #define FILEINFO_INFO_FAIL 3 /* GetFileInformationByHandle() failed */ | |
249 | + | |
250 | #endif /* VIM__H */ | |
251 | *** ../vim-7.3.171/src/version.c 2011-05-05 14:26:37.000000000 +0200 | |
252 | --- src/version.c 2011-05-05 16:39:35.000000000 +0200 | |
253 | *************** | |
254 | *** 716,717 **** | |
255 | --- 716,719 ---- | |
256 | { /* Add new patch number below this line */ | |
257 | + /**/ | |
258 | + 172, | |
259 | /**/ | |
260 | ||
261 | -- | |
262 | Q: What is a patch 22? | |
263 | A: A patch you need to include to make it possible to include patches. | |
264 | ||
265 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
266 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
267 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
268 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |