changeset 29556:261069440cb1 v9.0.0119

patch 9.0.0119: tiny chance that creating a backup file fails Commit: https://github.com/vim/vim/commit/dbdcc799109f0893856f07e03214206723cfdcf6 Author: K.Takata <kentkt@csc.jp> Date: Sun Jul 31 11:50:42 2022 +0100 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 https://github.com/vim/vim/issues/10821)
author Bram Moolenaar <Bram@vim.org>
date Sun, 31 Jul 2022 13:00:03 +0200
parents 72a842b8f99f
children 5f8dbafb0055
files src/bufwrite.c src/version.c
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/bufwrite.c
+++ b/src/bufwrite.c
@@ -1208,14 +1208,22 @@ buf_write(
 		// 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;
+		    }
 		}
-		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
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    119,
+/**/
     118,
 /**/
     117,