bug-texinfo
[Top][All Lists]
Advanced

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

Re: install-info can "corrupt" dir file if interrupted.


From: Gavin Smith
Subject: Re: install-info can "corrupt" dir file if interrupted.
Date: Sat, 3 Dec 2022 18:26:26 +0000

On Sat, Dec 03, 2022 at 07:52:46PM +0200, Eli Zaretskii wrote:
> > From: Gavin Smith <gavinsmith0123@gmail.com>
> > Date: Sat, 3 Dec 2022 15:25:20 +0000
> > Cc: Texinfo <bug-texinfo@gnu.org>
> > 
> > The report was dir file corruption if install-info was interrupted.
> > 
> > I've attempted to fix this issue by creating a temporary file with
> > mkstemp, and then renaming it.  I've added the Gnulib module for mkstemp
> > as it will not exist on MS-Windows.
> 
> The rename operation is not atomic on MS-Windows, only on Posix systems.

Not a big deal.

> Moreover, the MS runtime implements 'rename' in a way that fails if the
> destination exists.  So you will need the Gnulib replacement for it.

That is quite a big difference.

It's fairly easy to add the Gnulib module, although it appears
to bring in quite a few dependencies on other modules.  I don't want
to add any more Gnulib modules than necessary (size, configure run time,
complexity), so I wonder whether there would be be a simple work-around
of deleting the file first:

diff --git a/install-info/install-info.c b/install-info/install-info.c
index ef73a8855d..d6b331d33a 100644
--- a/install-info/install-info.c
+++ b/install-info/install-info.c
@@ -1053,6 +1053,16 @@ output_dirfile (char *dirfile, int dir_nlines, struct 
line_data *dir_lines,
 
   /* Update dir file atomically.  This stops the dir file being corrupted
      if install-info is interrupted. */
+
+#ifdef _WIN32
+  /* rename on MS-Windows will not replace an existing file */
+  if (remove (dirfile) == -1)
+    {
+      perror (dirfile);
+      return;
+    }
+#endif
+
   if (rename (tempname, dirfile) == -1)
     perror (tempname);
 }

WDYT?



reply via email to

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