This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: [WAS: Re: Why is GCJ shy of overwriting a .class file?]
- From: Ranjit Mathew <rmathew at hotmail dot com>
- To: java-patches at gcc dot gnu dot org
- Cc: aph at redhat dot com
- Date: Fri, 08 Nov 2002 17:59:36 +0530
- Subject: Patch: [WAS: Re: Why is GCJ shy of overwriting a .class file?]
- References: <aqg47v$eq8$1@main.gmane.org> <15819.38400.682938.635422@cuddles.cambridge.redhat.com> <aqg5uq$kg4$1@main.gmane.org> <aqg7jp$pjk$1@main.gmane.org> <15819.43037.411109.59361@cuddles.cambridge.redhat.com>
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/