1
0
forked from aniani/vim

patch 9.0.0119: tiny chance that creating a backup file fails

Problem:    Tiny chance that creating a backup file fails.
Solution:   Check for EEXIST error. (Ken Takata, closes #10821)
This commit is contained in:
K.Takata
2022-07-31 11:50:42 +01:00
committed by Bram Moolenaar
parent 750209459c
commit dbdcc79910
2 changed files with 13 additions and 3 deletions

View File

@@ -1208,14 +1208,22 @@ buf_write(
// First find a file name that doesn't exist yet (use some // First find a file name that doesn't exist yet (use some
// arbitrary numbers). // arbitrary numbers).
STRCPY(IObuff, fname); STRCPY(IObuff, fname);
fd = -1;
for (i = 4913; ; i += 123) for (i = 4913; ; i += 123)
{ {
sprintf((char *)gettail(IObuff), "%d", i); sprintf((char *)gettail(IObuff), "%d", i);
if (mch_lstat((char *)IObuff, &st) < 0) if (mch_lstat((char *)IObuff, &st) < 0)
break; {
} fd = mch_open((char *)IObuff,
fd = mch_open((char *)IObuff,
O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm); 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 if (fd < 0) // can't write in directory
backup_copy = TRUE; backup_copy = TRUE;
else else

View File

@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
119,
/**/ /**/
118, 118,
/**/ /**/