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.040 < prev    next >
Encoding:
Internet Message Format  |  2001-10-29  |  5.8 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.0.040
  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.040
  11. Problem:    When 'fileencoding' is invalid and writing fails because of
  12.         this, the original file is gone. (Eric Carlier)
  13. Solution:   Restore the original file from the backup.
  14. Files:        src/fileio.c
  15.  
  16.  
  17. *** ../vim60.39/src/fileio.c    Thu Sep 20 18:09:15 2001
  18. --- src/fileio.c    Tue Oct 30 19:59:18 2001
  19. ***************
  20. *** 2183,2189 ****
  21.       int            backup_copy = FALSE; /* copy the original file? */
  22.       int            dobackup;
  23.       char_u        *ffname;
  24. !     char_u        *wfname;        /* name of file to write to */
  25.       char_u        *s;
  26.       char_u        *ptr;
  27.       char_u        c;
  28. --- 2183,2189 ----
  29.       int            backup_copy = FALSE; /* copy the original file? */
  30.       int            dobackup;
  31.       char_u        *ffname;
  32. !     char_u        *wfname = NULL;    /* name of file to write to */
  33.       char_u        *s;
  34.       char_u        *ptr;
  35.       char_u        c;
  36. ***************
  37. *** 3016,3022 ****
  38.       if (got_int)
  39.       {
  40.           errmsg = (char_u *)_(e_interr);
  41. !         goto fail;
  42.       }
  43.       }
  44.   
  45. --- 3016,3022 ----
  46.       if (got_int)
  47.       {
  48.           errmsg = (char_u *)_(e_interr);
  49. !         goto restore_backup;
  50.       }
  51.       }
  52.   
  53. ***************
  54. *** 3030,3036 ****
  55.       if (mch_has_resource_fork(fname))
  56.       {
  57.           errmsg = (char_u *)_("The resource fork will be lost (use ! to override)");
  58. !         goto fail;
  59.       }
  60.   #endif
  61.   
  62. --- 3030,3036 ----
  63.       if (mch_has_resource_fork(fname))
  64.       {
  65.           errmsg = (char_u *)_("The resource fork will be lost (use ! to override)");
  66. !         goto restore_backup;
  67.       }
  68.   #endif
  69.   
  70. ***************
  71. *** 3119,3125 ****
  72.           if (wfname == NULL)    /* Can't write without a tempfile! */
  73.           {
  74.               errmsg = (char_u *)_("E214: Can't find temp file for writing");
  75. !             goto fail;
  76.           }
  77.           }
  78.   #  endif
  79. --- 3119,3125 ----
  80.           if (wfname == NULL)    /* Can't write without a tempfile! */
  81.           {
  82.               errmsg = (char_u *)_("E214: Can't find temp file for writing");
  83. !             goto restore_backup;
  84.           }
  85.           }
  86.   #  endif
  87. ***************
  88. *** 3137,3143 ****
  89.       if (!forceit)
  90.       {
  91.           errmsg = (char_u *)_("E213: Cannot convert (use ! to write without conversion)");
  92. !         goto fail;
  93.       }
  94.       notconverted = TRUE;
  95.       }
  96. --- 3137,3143 ----
  97.       if (!forceit)
  98.       {
  99.           errmsg = (char_u *)_("E213: Cannot convert (use ! to write without conversion)");
  100. !         goto restore_backup;
  101.       }
  102.       notconverted = TRUE;
  103.       }
  104. ***************
  105. *** 3156,3163 ****
  106.               : (O_CREAT | O_TRUNC))
  107.               , 0666)) < 0)
  108.       {
  109. -     struct stat st;
  110.       /*
  111.        * A forced write will try to create a new file if the old one is
  112.        * still readonly. This may also happen when the directory is
  113. --- 3156,3161 ----
  114. ***************
  115. *** 3196,3233 ****
  116.           }
  117.           }
  118.       }
  119. !     /*
  120. !      * If we failed to open the file, we don't need a backup. Throw it
  121. !      * away.  If we moved or removed the original file try to put the
  122. !      * backup in its place.
  123. !      */
  124. !     if (backup != NULL && wfname == fname)
  125.       {
  126. !         if (backup_copy)
  127.           {
  128. !         /*
  129. !          * There is a small chance that we removed the original, try
  130. !          * to move the copy in its place.
  131. !          * This may not work if the vim_rename() fails.
  132. !          * In that case we leave the copy around.
  133. !          */
  134. !         /* If file does not exist, put the copy in its place */
  135. !         if (mch_stat((char *)fname, &st) < 0)
  136.               vim_rename(backup, fname);
  137. !         /* if original file does exist throw away the copy */
  138. !         if (mch_stat((char *)fname, &st) >= 0)
  139. !             mch_remove(backup);
  140. !         }
  141. !         else
  142. !         {
  143. !         /* try to put the original file back */
  144. !         vim_rename(backup, fname);
  145.           }
  146. -     }
  147.   
  148. !     /* if original file no longer exists give an extra warning */
  149. !     if (!newfile && mch_stat((char *)fname, &st) < 0)
  150. !         end = 0;
  151.   
  152.   #ifdef FEAT_MBYTE
  153.       if (wfname != fname)
  154. --- 3194,3237 ----
  155.           }
  156.           }
  157.       }
  158. ! restore_backup:
  159.       {
  160. !         struct stat st;
  161. !         /*
  162. !          * If we failed to open the file, we don't need a backup. Throw it
  163. !          * away.  If we moved or removed the original file try to put the
  164. !          * backup in its place.
  165. !          */
  166. !         if (backup != NULL && wfname == fname)
  167.           {
  168. !         if (backup_copy)
  169. !         {
  170. !             /*
  171. !              * There is a small chance that we removed the original,
  172. !              * try to move the copy in its place.
  173. !              * This may not work if the vim_rename() fails.
  174. !              * In that case we leave the copy around.
  175. !              */
  176. !             /* If file does not exist, put the copy in its place */
  177. !             if (mch_stat((char *)fname, &st) < 0)
  178. !             vim_rename(backup, fname);
  179. !             /* if original file does exist throw away the copy */
  180. !             if (mch_stat((char *)fname, &st) >= 0)
  181. !             mch_remove(backup);
  182. !         }
  183. !         else
  184. !         {
  185. !             /* try to put the original file back */
  186.               vim_rename(backup, fname);
  187. !         }
  188.           }
  189.   
  190. !         /* if original file no longer exists give an extra warning */
  191. !         if (!newfile && mch_stat((char *)fname, &st) < 0)
  192. !         end = 0;
  193. !     }
  194.   
  195.   #ifdef FEAT_MBYTE
  196.       if (wfname != fname)
  197. *** ../vim60.39/src/version.c    Tue Oct 30 14:52:27 2001
  198. --- src/version.c    Tue Oct 30 20:01:33 2001
  199. ***************
  200. *** 608,609 ****
  201. --- 608,611 ----
  202.   {   /* Add new patch number below this line */
  203. + /**/
  204. +     40,
  205.   /**/
  206.  
  207. -- 
  208. VOICE OVER: As the horrendous Black Beast lunged forward, escape for Arthur
  209.             and his knights seemed hopeless,  when, suddenly ... the animator
  210.             suffered a fatal heart attack.
  211. ANIMATOR:   Aaaaagh!
  212. VOICE OVER: The cartoon peril was no more ... The Quest for Holy Grail could
  213.             continue.
  214.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  215.  
  216.  ///  Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net  \\\
  217. (((   Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim   )))
  218.  \\\  Help me helping AIDS orphans in Uganda - http://iccf-holland.org  ///
  219.