diff options
author | K.Takata <kentkt@csc.jp> | 2022-07-31 11:50:42 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-07-31 11:50:42 +0100 |
commit | dbdcc799109f0893856f07e03214206723cfdcf6 (patch) | |
tree | 9f8ccc5286af0c5e24330bc4d7d6996e3c30d4d7 /src/bufwrite.c | |
parent | 750209459c9e54030409afe8f4ad59570600b5c4 (diff) | |
download | vim-git-dbdcc799109f0893856f07e03214206723cfdcf6.tar.gz |
patch 9.0.0119: tiny chance that creating a backup file failsv9.0.0119
Problem: Tiny chance that creating a backup file fails.
Solution: Check for EEXIST error. (Ken Takata, closes #10821)
Diffstat (limited to 'src/bufwrite.c')
-rw-r--r-- | src/bufwrite.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bufwrite.c b/src/bufwrite.c index 8db426626..d7c303476 100644 --- 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 |