Patch 9.0.0119

5 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 31, 2022, 6:51:30 AM7/31/22
to vim...@googlegroups.com

Patch 9.0.0119
Problem: Tiny chance that creating a backup file fails.
Solution: Check for EEXIST error. (Ken Takata, closes #10821)
Files: src/bufwrite.c


*** ../vim-9.0.0118/src/bufwrite.c 2022-05-09 19:06:06.000000000 +0100
--- src/bufwrite.c 2022-07-31 11:47:43.353783544 +0100
***************
*** 1208,1221 ****
// First find a file name that doesn't exist yet (use some
// arbitrary numbers).
STRCPY(IObuff, fname);
for (i = 4913; ; i += 123)
{
sprintf((char *)gettail(IObuff), "%d", i);
if (mch_lstat((char *)IObuff, &st) < 0)
break;
}
- fd = mch_open((char *)IObuff,
- O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
if (fd < 0) // can't write in directory
backup_copy = TRUE;
else
--- 1208,1229 ----
// First find a file name that doesn't exist yet (use some
// arbitrary numbers).
STRCPY(IObuff, fname);
+ fd = -1;
for (i = 4913; ; i += 123)
{
sprintf((char *)gettail(IObuff), "%d", i);
if (mch_lstat((char *)IObuff, &st) < 0)
+ {
+ fd = mch_open((char *)IObuff,
+ O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
+ if (fd < 0 && errno == EEXIST)
+ // If the same file name is created by another
+ // process between lstat() and open(), find another
+ // name.
+ continue;
break;
+ }
}
if (fd < 0) // can't write in directory
backup_copy = TRUE;
else
*** ../vim-9.0.0118/src/version.c 2022-07-31 11:37:16.451058499 +0100
--- src/version.c 2022-07-31 11:50:05.289659017 +0100
***************
*** 737,738 ****
--- 737,740 ----
{ /* Add new patch number below this line */
+ /**/
+ 119,
/**/

--
hundred-and-one symptoms of being an internet addict:
203. You're an active member of more than 20 newsgroups.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages