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: Eli Zaretskii
Subject: Re: install-info can "corrupt" dir file if interrupted.
Date: Sat, 03 Dec 2022 20:54:42 +0200

> From: Gavin Smith <gavinsmith0123@gmail.com>
> Date: Sat, 3 Dec 2022 18:26:26 +0000
> Cc: pedrum@gmail.com, bug-texinfo@gnu.org
> 
> > 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)

I can sympathize with this.

> 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?

I suggest the other way around: try renaming, and if it fails, remove and
retry renaming.  This way, if remove fails, it fails the entire renaming
operation, and you don't need to deal with remove failing due to unrelated
reasons.



reply via email to

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