edit-util: do not try to recreate temp file if missing
authorMike Yuan <me@yhndnzj.com>
Sun, 11 Aug 2024 13:41:30 +0000 (15:41 +0200)
committerLuca Boccassi <bluca@debian.org>
Thu, 15 Aug 2024 13:04:41 +0000 (14:04 +0100)
We initially read from temp file, then strip it, and write
back to it. If the file suddenly disappeared during the process,
it indicates someone else is touching our temp file
behind our back. Let's not silently continue.

(cherry picked from commit 3b5b2ff8fa6413afc2e5a058ea8281a58a4c691d)

src/shared/edit-util.c

index cfb2828f4e3b4c7caba8c3218d492cac8b23841e..b0496032f7b8cf5e0bc1aa67846a4c7576454d7f 100644 (file)
@@ -357,7 +357,7 @@ static int strip_edit_temp_file(EditFile *e) {
                 return 1; /* Contents have real changes */
 
         r = write_string_file(e->temp, new_contents,
-                              WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_TRUNCATE | WRITE_STRING_FILE_AVOID_NEWLINE);
+                              WRITE_STRING_FILE_TRUNCATE | WRITE_STRING_FILE_AVOID_NEWLINE);
         if (r < 0)
                 return log_error_errno(r, "Failed to strip temporary file '%s': %m", e->temp);