]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0119: tiny chance that creating a backup file fails v9.0.0119
authorK.Takata <kentkt@csc.jp>
Sun, 31 Jul 2022 10:50:42 +0000 (11:50 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 31 Jul 2022 10:50:42 +0000 (11:50 +0100)
Problem:    Tiny chance that creating a backup file fails.
Solution:   Check for EEXIST error. (Ken Takata, closes #10821)

src/bufwrite.c
src/version.c

index 8db426626507101621880e7aece6b96264f4a029..d7c3034766b6a11186d2480cab44d545a39325eb 100644 (file)
@@ -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
index 5f276d4b79c6222bf5b325e52e8758002dcb29af..0a38f39677d766b2c3b4817ce76bb233cce06a07 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    119,
 /**/
     118,
 /**/