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 / 6.0.079 < prev    next >
Encoding:
Internet Message Format  |  2001-11-04  |  3.4 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.0.079
  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 6.0.079
  11. Problem:    When "W" is in 'cpoptions' and 'backupcopy' is "no" or "auto", can
  12.         still overwrite a read-only file, because it's renamed. (Gary
  13.         Holloway)
  14. Solution:   Add a check for a read-only file before renaming the file to
  15.         become the backup.
  16. Files:        src/fileio.c
  17.  
  18.  
  19. *** ../vim60.78/src/fileio.c    Tue Oct 30 20:35:08 2001
  20. --- src/fileio.c    Mon Nov  5 19:37:58 2001
  21. ***************
  22. *** 2204,2209 ****
  23. --- 2204,2211 ----
  24.       int            device = FALSE;        /* writing to a device */
  25.       struct stat        st_old;
  26.       int            prev_got_int = got_int;
  27. +     int            file_readonly = FALSE;  /* overwritten file is read-only */
  28. +     static char        *err_readonly = "is read-only (cannot override: \"W\" in 'cpoptions')";
  29.   #if defined(UNIX) || defined(__EMX__XX)        /*XXX fix me sometime? */
  30.       int            made_writable = FALSE;  /* 'w' bit has been set */
  31.   #endif
  32. ***************
  33. *** 2540,2546 ****
  34.        * Check if the file is really writable (when renaming the file to
  35.        * make a backup we won't discover it later).
  36.        */
  37. !     if (!forceit && (
  38.   # ifdef USE_MCH_ACCESS
  39.   #  ifdef UNIX
  40.               (perm & 0222) == 0 ||
  41. --- 2542,2548 ----
  42.        * Check if the file is really writable (when renaming the file to
  43.        * make a backup we won't discover it later).
  44.        */
  45. !     file_readonly = (
  46.   # ifdef USE_MCH_ACCESS
  47.   #  ifdef UNIX
  48.               (perm & 0222) == 0 ||
  49. ***************
  50. *** 2548,2558 ****
  51.               mch_access((char *)fname, W_OK)
  52.   # else
  53.               (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
  54. !             ? TRUE : (close(fd), FALSE)
  55.   # endif
  56. !             ))
  57.       {
  58. !         errmsg = (char_u *)_("is read-only (use ! to override)");
  59.           goto fail;
  60.       }
  61.   
  62. --- 2550,2564 ----
  63.               mch_access((char *)fname, W_OK)
  64.   # else
  65.               (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
  66. !                            ? TRUE : (close(fd), FALSE)
  67.   # endif
  68. !             );
  69. !     if (!forceit && file_readonly)
  70.       {
  71. !         if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
  72. !         errmsg = (char_u *)_(err_readonly);
  73. !         else
  74. !         errmsg = (char_u *)_("is read-only (use ! to override)");
  75.           goto fail;
  76.       }
  77.   
  78. ***************
  79. *** 2895,2900 ****
  80. --- 2901,2919 ----
  81.   
  82.           /*
  83.            * Make a backup by renaming the original file.
  84. +          */
  85. +         /*
  86. +          * If 'cpoptions' includes the "W" flag, we don't want to
  87. +          * overwrite a read-only file.  But rename may be possible
  88. +          * anyway, thus we need an extra check here.
  89. +          */
  90. +         if (file_readonly && vim_strchr(p_cpo, CPO_FWRITE) != NULL)
  91. +         {
  92. +         errmsg = (char_u *)_(err_readonly);
  93. +         goto fail;
  94. +         }
  95. +         /*
  96.            *
  97.            * Form the backup file name - change path/fo.o.h to
  98.            * path/fo.o.h.bak Try all directories in 'backupdir', first one
  99. *** ../vim60.78/src/version.c    Mon Nov  5 13:16:21 2001
  100. --- src/version.c    Mon Nov  5 20:31:42 2001
  101. ***************
  102. *** 608,609 ****
  103. --- 608,611 ----
  104.   {   /* Add new patch number below this line */
  105. + /**/
  106. +     79,
  107.   /**/
  108.  
  109. -- 
  110. hundred-and-one symptoms of being an internet addict:
  111. 1. You actually wore a blue ribbon to protest the Communications Decency Act.
  112.  
  113.  ///  Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net  \\\
  114. (((   Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim   )))
  115.  \\\  Help me helping AIDS orphans in Uganda - http://iccf-holland.org  ///
  116.