]> git.pld-linux.org Git - packages/vim.git/blob - 7.1.017
- typo
[packages/vim.git] / 7.1.017
1 To: vim-dev@vim.org
2 Subject: patch 7.1.017
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.1.017
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
15
16
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
19 ***************
20 *** 2912,2933 ****
21   }
22   
23   /*
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.
26    */
27       static int
28   check_readonly(forceit, buf)
29       int               *forceit;
30       buf_T     *buf;
31   {
32 !     if (!*forceit && buf->b_p_ro)
33       {
34   #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
35         if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL)
36         {
37             char_u      buff[IOSIZE];
38   
39 !           dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"),
40                     buf->b_fname);
41   
42             if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES)
43 --- 2912,2946 ----
44   }
45   
46   /*
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.
50    */
51       static int
52   check_readonly(forceit, buf)
53       int               *forceit;
54       buf_T     *buf;
55   {
56 !     struct stat       st;
57
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))))
65       {
66   #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
67         if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL)
68         {
69             char_u      buff[IOSIZE];
70   
71 !           if (buf->b_p_ro)
72 !               dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"),
73 !                   buf->b_fname);
74 !           else
75 !               dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"),
76                     buf->b_fname);
77   
78             if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES)
79 ***************
80 *** 2941,2949 ****
81 --- 2954,2967 ----
82         }
83         else
84   #endif
85 +       if (buf->b_p_ro)
86             EMSG(_(e_readonly));
87 +       else
88 +           EMSG2(_("E505: \"%s\" is read-only (add ! to override)"),
89 +                   buf->b_fname);
90         return TRUE;
91       }
92
93       return FALSE;
94   }
95   
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
98 ***************
99 *** 424,430 ****
100          */
101         if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
102         {
103 !           filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option"), 0);
104             msg_end();
105             msg_scroll = msg_save;
106             return FAIL;
107 --- 424,430 ----
108          */
109         if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
110         {
111 !           filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0);
112             msg_end();
113             msg_scroll = msg_save;
114             return FAIL;
115 ***************
116 *** 2734,2739 ****
117 --- 2734,2765 ----
118   #endif
119   
120   /*
121 +  * Return TRUE if a file appears to be read-only from the file permissions.
122 +  */
123 +     int
124 + check_file_readonly(fname, perm)
125 +     char_u    *fname;         /* full path to file */
126 +     int               perm;           /* known permissions on file */
127 + {
128 + #ifndef USE_MCH_ACCESS
129 +     int           fd = 0;
130 + #endif
131
132 +     return (
133 + #ifdef USE_MCH_ACCESS
134 + # ifdef UNIX
135 +       (perm & 0222) == 0 ||
136 + # endif
137 +       mch_access((char *)fname, W_OK)
138 + #else
139 +       (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
140 +                                       ? TRUE : (close(fd), FALSE)
141 + #endif
142 +       );
143 + }
144
145
146 + /*
147    * buf_write() - write to file "fname" lines "start" through "end"
148    *
149    * We do our own buffering here because fwrite() is so slow.
150 ***************
151 *** 3219,3235 ****
152          * Check if the file is really writable (when renaming the file to
153          * make a backup we won't discover it later).
154          */
155 !       file_readonly = (
156 ! # ifdef USE_MCH_ACCESS
157 ! #  ifdef UNIX
158 !                   (perm & 0222) == 0 ||
159 ! #  endif
160 !                   mch_access((char *)fname, W_OK)
161 ! # else
162 !                   (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
163 !                                                  ? TRUE : (close(fd), FALSE)
164 ! # endif
165 !                   );
166         if (!forceit && file_readonly)
167         {
168             if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
169 --- 3245,3252 ----
170          * Check if the file is really writable (when renaming the file to
171          * make a backup we won't discover it later).
172          */
173 !       file_readonly = check_file_readonly(fname, (int)perm);
174
175         if (!forceit && file_readonly)
176         {
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
180 ***************
181 *** 2,7 ****
182 --- 2,8 ----
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
192 ***************
193 *** 668,669 ****
194 --- 668,671 ----
195   {   /* Add new patch number below this line */
196 + /**/
197 +     17,
198   /**/
199
200 -- 
201 CUSTOMER:     Well, can you hang around a couple of minutes?  He won't be
202               long.
203 MORTICIAN:    Naaah, I got to go on to Robinson's -- they've lost nine today.
204 CUSTOMER:     Well, when is your next round?
205 MORTICIAN:    Thursday.
206 DEAD PERSON:  I think I'll go for a walk.
207                                   The Quest for the Holy Grail (Monty Python)
208
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    ///
This page took 0.296964 seconds and 3 git commands to generate.