Subject: Re: bug#8496: some file locking code in insert-file-contents cannot be right

From: Eli Zaretskii <[email-masked]>
Date: Thu, 14 Apr 2011 02:48:28 -0400

> Date: Wed, 13 Apr 2011 17:40:49 -0700
> From: Paul Eggert <[email-masked]>
> 
> As a result of the "mark unexported symbols 'static'" patch that I'm
> working on, in the Emacs trunk I found some file-locking code inside
> insert-file-contents that cannot be right:
> 
>      if (NILP (visit) && inserted > 0)
>        {
>    #ifdef CLASH_DETECTION
> 	 if (!NILP (BVAR (current_buffer, file_truename))
> 	     /* Make binding buffer-file-name to nil effective.  */
> 	     && !NILP (BVAR (current_buffer, filename))
> 	     && SAVE_MODIFF >= MODIFF)
> 	   we_locked_file = 1;
>    #endif /* CLASH_DETECTION */
> 	 prepare_to_modify_buffer (GPT, GPT, NULL);
>        }
> 
> The above code is equivalent to a no-op, since 'inserted' must
> be zero here.

In Emacs 21.4a, the corresponding code was this:

    if (!NILP (visit))
      {
	...
  #ifdef CLASH_DETECTION
	if (NILP (handler))
	  {
	    if (!NILP (current_buffer->file_truename))
	      unlock_file (current_buffer->file_truename);
	    unlock_file (filename);
	  }
  #endif /* CLASH_DETECTION */

The change to the present form was between 21.4a and 22.1.  It appears
in the trunk history as part of a huge merge from a branch, probably
the Emacs 22.1 release branch.  I need more forensic work to find out
why the change was made, but at this point it certainly looks like
someone goofed with the condition.

What platforms use CLASH_DETECTION?