Patch: [WAS: Re: Why is GCJ shy of overwriting a .class file?]

Ranjit Mathew rmathew@hotmail.com
Fri Nov 8 04:29:00 GMT 2002


Ok, here's the reworked patch proposal :-

ChangeLog:

2002-11-08  Ranjit Mathew <rmathew@hotmail.com>,
             Andrew Haley <aph@redhat.com>

     * gcc/java/jcf-write.c (write_classfile): Remove target
     class file, if it exists, before renaming the temporary
     class file to it.

--------------------------- 8< -----------------------------
--- jcf-write.c Fri Nov  8 17:00:02 2002
+++ jcf-write.c Fri Nov  8 17:52:25 2002
@@ -3423,4 +3423,13 @@
        if (fclose (stream))
         fatal_io_error ("error closing %s", temporary_file_name);
+
+      /* If a file named by the string pointed to by `new' exists
+         prior to the call to the `rename' function, the bahaviour
+         is implementation-defined.  ISO 9899-1990 7.9.4.2.
+
+         For example, on Win32 with MSVCRT, it is an error. */
+
+      remove (class_file_name);
+
        if (rename (temporary_file_name, class_file_name) == -1)
         {
--------------------------- 8< -----------------------------

Ranjit.

Andrew Haley wrote:
> Ranjit Mathew writes:
>  > 
>  > I read the MSDN documentation and found that MSVCRT
>  > would return an error for rename( ) if the file
>  > already exists, unlike Unix.
>  > 
>  > How does the following look?
>  > --------------------------- 8< -----------------------------------
>  > --- jcf-write.c Fri Nov  8 17:00:02 2002
>  > +++ jcf-write.c Fri Nov  8 17:02:34 2002
>  > @@ -3423,4 +3423,8 @@
>  >         if (fclose (stream))
>  >          fatal_io_error ("error closing %s", temporary_file_name);
>  > +
>  > +      /* On Win32, renaming to an existing file is an error */
>  > +      remove (class_file_name);
>  > +
>  >         if (rename (temporary_file_name, class_file_name) == -1)
>  >          {
>  > --------------------------- 8< -----------------------------------
> 
> OK.
> 
> I'd add more commentary:
> 
> /* If a file named by the string pointed to by `new' exists prior to
>    the call to the `rename' function, the bahaviour is
>    implementation-defined.  ISO 9899-1990 7.9.4.2.  */
> 
> Andrew.
> 


-- 
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/





More information about the Java-patches mailing list