texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Atomic dir update


From: Gavin D. Smith
Subject: branch master updated: Atomic dir update
Date: Sat, 03 Dec 2022 09:41:18 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 93162b78d8 Atomic dir update
93162b78d8 is described below

commit 93162b78d84f731710025b300bc0cd7ca8b14347
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Dec 3 14:41:08 2022 +0000

    Atomic dir update
    
    * install-info/install-info.c (output_dirfile): Write to
    file created by mkstemp first, then rename this to the real
    output file.
    * TODO: Remove item.
    
    Report from Pedrum Mohageri, bug-texinfo, November 2015.
---
 ChangeLog                   | 11 +++++++++++
 TODO                        |  3 ---
 install-info/install-info.c | 14 ++++++++++++--
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 253a0c4afe..4d7f21fb1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-12-03  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Atomic dir update
+
+       * install-info/install-info.c (output_dirfile): Write to
+       file created by mkstemp first, then rename this to the real
+       output file. 
+       * TODO: Remove item.
+
+       Report from Pedrum Mohageri, bug-texinfo, November 2015.
+
 2022-12-03  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * doc/texinfo.texi (Directory Category), TODO: Do not refer
diff --git a/TODO b/TODO
index 9dfcb88e98..c95542417f 100644
--- a/TODO
+++ b/TODO
@@ -91,9 +91,6 @@ If you are interested in working on any of these, email 
bug-texinfo@gnu.org.
   - Handle M-n, C-u m, and C-u g like Emacs Info (opening new windows).
 
 * install-info:
-  - replace dir file atomically in case install-info is interrupted
-    (Pedrum Mohageri,
-    https://lists.gnu.org/archive/html/bug-texinfo/2015-11/msg00027.html)
   - install-info --dir-file=dir2 --entry=info foo.info installs garbage
     from the misformatted --entry (and no entries from foo.info).
   - support info dir entries for other than the current info file name;
diff --git a/install-info/install-info.c b/install-info/install-info.c
index 8950288f6b..ef73a8855d 100644
--- a/install-info/install-info.c
+++ b/install-info/install-info.c
@@ -923,14 +923,19 @@ output_dirfile (char *dirfile, int dir_nlines, struct 
line_data *dir_lines,
   int n_entries_added = 0;
   int i;
   FILE *output;
+  int tempfile; /* moved to dirfile when finished */
+  char tempname[] = "infodirXXXXXX";
 
+  tempfile = mkstemp (tempname);
   if (compression_program)
     {
-      char *command = concat (compression_program, ">", dirfile);
+      char *command;
+      close (tempfile);
+      command = concat (compression_program, ">", tempname);
       output = popen (command, "w");
     }
   else
-    output = fopen (dirfile, "w");
+    output = fdopen (tempfile, "w");
 
   if (!output)
     {
@@ -1045,6 +1050,11 @@ output_dirfile (char *dirfile, int dir_nlines, struct 
line_data *dir_lines,
     pclose (output);
   else
     fclose (output);
+
+  /* Update dir file atomically.  This stops the dir file being corrupted
+     if install-info is interrupted. */
+  if (rename (tempname, dirfile) == -1)
+    perror (tempname);
 }
 
 /* Read through the input LINES, to find the section names and the



reply via email to

[Prev in Thread] Current Thread [Next in Thread]