home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.1 / 7.1.017 < prev    next >
Encoding:
Internet Message Format  |  2007-11-19  |  6.6 KB

  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. !     /* Handle a file being readonly when the 'readonly' option is set or when
  58. !      * the file exists and permissions are read-only.
  59. !      * We will send 0777 to check_file_readonly(), as the "perm" variable is
  60. !      * important for device checks but not here. */
  61. !     if (!*forceit && (buf->b_p_ro
  62. !         || (mch_stat((char *)buf->b_ffname, &st) >= 0
  63. !             && check_file_readonly(buf->b_ffname, 0777))))
  64.       {
  65.   #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
  66.       if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL)
  67.       {
  68.           char_u    buff[IOSIZE];
  69.   
  70. !         if (buf->b_p_ro)
  71. !         dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"),
  72. !             buf->b_fname);
  73. !         else
  74. !         dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"),
  75.               buf->b_fname);
  76.   
  77.           if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES)
  78. ***************
  79. *** 2941,2949 ****
  80. --- 2954,2967 ----
  81.       }
  82.       else
  83.   #endif
  84. +     if (buf->b_p_ro)
  85.           EMSG(_(e_readonly));
  86. +     else
  87. +         EMSG2(_("E505: \"%s\" is read-only (add ! to override)"),
  88. +             buf->b_fname);
  89.       return TRUE;
  90.       }
  91.       return FALSE;
  92.   }
  93.   
  94. *** ../vim-7.1.016/src/fileio.c    Thu May 10 19:32:17 2007
  95. --- src/fileio.c    Thu Jun 28 21:54:18 2007
  96. ***************
  97. *** 424,430 ****
  98.        */
  99.       if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
  100.       {
  101. !         filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option"), 0);
  102.           msg_end();
  103.           msg_scroll = msg_save;
  104.           return FAIL;
  105. --- 424,430 ----
  106.        */
  107.       if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
  108.       {
  109. !         filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0);
  110.           msg_end();
  111.           msg_scroll = msg_save;
  112.           return FAIL;
  113. ***************
  114. *** 2734,2739 ****
  115. --- 2734,2765 ----
  116.   #endif
  117.   
  118.   /*
  119. +  * Return TRUE if a file appears to be read-only from the file permissions.
  120. +  */
  121. +     int
  122. + check_file_readonly(fname, perm)
  123. +     char_u    *fname;        /* full path to file */
  124. +     int        perm;        /* known permissions on file */
  125. + {
  126. + #ifndef USE_MCH_ACCESS
  127. +     int        fd = 0;
  128. + #endif
  129. +     return (
  130. + #ifdef USE_MCH_ACCESS
  131. + # ifdef UNIX
  132. +     (perm & 0222) == 0 ||
  133. + # endif
  134. +     mch_access((char *)fname, W_OK)
  135. + #else
  136. +     (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
  137. +                     ? TRUE : (close(fd), FALSE)
  138. + #endif
  139. +     );
  140. + }
  141. + /*
  142.    * buf_write() - write to file "fname" lines "start" through "end"
  143.    *
  144.    * We do our own buffering here because fwrite() is so slow.
  145. ***************
  146. *** 3219,3235 ****
  147.        * Check if the file is really writable (when renaming the file to
  148.        * make a backup we won't discover it later).
  149.        */
  150. !     file_readonly = (
  151. ! # ifdef USE_MCH_ACCESS
  152. ! #  ifdef UNIX
  153. !             (perm & 0222) == 0 ||
  154. ! #  endif
  155. !             mch_access((char *)fname, W_OK)
  156. ! # else
  157. !             (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
  158. !                            ? TRUE : (close(fd), FALSE)
  159. ! # endif
  160. !             );
  161.       if (!forceit && file_readonly)
  162.       {
  163.           if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
  164. --- 3245,3252 ----
  165.        * Check if the file is really writable (when renaming the file to
  166.        * make a backup we won't discover it later).
  167.        */
  168. !     file_readonly = check_file_readonly(fname, (int)perm);
  169.       if (!forceit && file_readonly)
  170.       {
  171.           if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
  172. *** ../vim-7.1.016/src/proto/fileio.pro    Sat May  5 19:59:00 2007
  173. --- src/proto/fileio.pro    Thu Jun 28 21:09:59 2007
  174. ***************
  175. *** 2,7 ****
  176. --- 2,8 ----
  177.   void filemess __ARGS((buf_T *buf, char_u *name, char_u *s, int attr));
  178.   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));
  179.   int prep_exarg __ARGS((exarg_T *eap, buf_T *buf));
  180. + int check_file_readonly __ARGS((char_u *fname, int perm));
  181.   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));
  182.   void msg_add_fname __ARGS((buf_T *buf, char_u *fname));
  183.   void msg_add_lines __ARGS((int insert_space, long lnum, long nchars));
  184. *** ../vim-7.1.016/src/version.c    Thu Jun 28 21:23:52 2007
  185. --- src/version.c    Thu Jun 28 21:49:29 2007
  186. ***************
  187. *** 668,669 ****
  188. --- 668,671 ----
  189.   {   /* Add new patch number below this line */
  190. + /**/
  191. +     17,
  192.   /**/
  193.  
  194. -- 
  195. CUSTOMER:     Well, can you hang around a couple of minutes?  He won't be
  196.               long.
  197. MORTICIAN:    Naaah, I got to go on to Robinson's -- they've lost nine today.
  198. CUSTOMER:     Well, when is your next round?
  199. MORTICIAN:    Thursday.
  200. DEAD PERSON:  I think I'll go for a walk.
  201.                                   The Quest for the Holy Grail (Monty Python)
  202.  
  203.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  204. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  205. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  206.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  207.