4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: ":confirm w" does give a prompt when 'readonly' is set, but not
12 when the file permissions are read-only. (Michael Schaap)
13 Solution: Provide a dialog in both situations. (Chris Lubinski)
14 Files: src/ex_cmds.c, src/fileio.c, src/proto/fileio.pro
17 *** ../vim-7.1.016/src/ex_cmds.c Tue Jun 19 11:54:23 2007
18 --- src/ex_cmds.c Tue Jun 19 22:37:25 2007
24 ! * Check if a buffer is read-only. Ask for overruling in a dialog.
25 ! * Return TRUE and give an error message when the buffer is readonly.
28 check_readonly(forceit, buf)
32 ! if (!*forceit && buf->b_p_ro)
34 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
35 if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL)
39 ! dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"),
42 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES)
47 ! * Check if a buffer is read-only (either 'readonly' option is set or file is
48 ! * read-only). Ask for overruling in a dialog. Return TRUE and give an error
49 ! * message when the buffer is readonly.
52 check_readonly(forceit, buf)
58 ! /* Handle a file being readonly when the 'readonly' option is set or when
59 ! * the file exists and permissions are read-only.
60 ! * We will send 0777 to check_file_readonly(), as the "perm" variable is
61 ! * important for device checks but not here. */
62 ! if (!*forceit && (buf->b_p_ro
63 ! || (mch_stat((char *)buf->b_ffname, &st) >= 0
64 ! && check_file_readonly(buf->b_ffname, 0777))))
66 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
67 if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL)
72 ! dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"),
75 ! dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"),
78 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES)
88 + EMSG2(_("E505: \"%s\" is read-only (add ! to override)"),
96 *** ../vim-7.1.016/src/fileio.c Thu May 10 19:32:17 2007
97 --- src/fileio.c Thu Jun 28 21:54:18 2007
101 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
103 ! filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option"), 0);
105 msg_scroll = msg_save;
109 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
111 ! filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0);
113 msg_scroll = msg_save;
121 + * Return TRUE if a file appears to be read-only from the file permissions.
124 + check_file_readonly(fname, perm)
125 + char_u *fname; /* full path to file */
126 + int perm; /* known permissions on file */
128 + #ifndef USE_MCH_ACCESS
133 + #ifdef USE_MCH_ACCESS
135 + (perm & 0222) == 0 ||
137 + mch_access((char *)fname, W_OK)
139 + (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
140 + ? TRUE : (close(fd), FALSE)
147 * buf_write() - write to file "fname" lines "start" through "end"
149 * We do our own buffering here because fwrite() is so slow.
152 * Check if the file is really writable (when renaming the file to
153 * make a backup we won't discover it later).
156 ! # ifdef USE_MCH_ACCESS
158 ! (perm & 0222) == 0 ||
160 ! mch_access((char *)fname, W_OK)
162 ! (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
163 ! ? TRUE : (close(fd), FALSE)
166 if (!forceit && file_readonly)
168 if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
170 * Check if the file is really writable (when renaming the file to
171 * make a backup we won't discover it later).
173 ! file_readonly = check_file_readonly(fname, (int)perm);
175 if (!forceit && file_readonly)
177 if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
178 *** ../vim-7.1.016/src/proto/fileio.pro Sat May 5 19:59:00 2007
179 --- src/proto/fileio.pro Thu Jun 28 21:09:59 2007
183 void filemess __ARGS((buf_T *buf, char_u *name, char_u *s, int attr));
184 int readfile __ARGS((char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, int flags));
185 int prep_exarg __ARGS((exarg_T *eap, buf_T *buf));
186 + int check_file_readonly __ARGS((char_u *fname, int perm));
187 int buf_write __ARGS((buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering));
188 void msg_add_fname __ARGS((buf_T *buf, char_u *fname));
189 void msg_add_lines __ARGS((int insert_space, long lnum, long nchars));
190 *** ../vim-7.1.016/src/version.c Thu Jun 28 21:23:52 2007
191 --- src/version.c Thu Jun 28 21:49:29 2007
195 { /* Add new patch number below this line */
201 CUSTOMER: Well, can you hang around a couple of minutes? He won't be
203 MORTICIAN: Naaah, I got to go on to Robinson's -- they've lost nine today.
204 CUSTOMER: Well, when is your next round?
206 DEAD PERSON: I think I'll go for a walk.
207 The Quest for the Holy Grail (Monty Python)
209 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
210 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
211 \\\ download, build and distribute -- http://www.A-A-P.org ///
212 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///