diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jar/Updater.java | 29 |
2 files changed, 36 insertions, 1 deletions
@@ -1,5 +1,13 @@ 2008-06-26 Andrew John Hughes <gnu_andrew@member.fsf.org> + PR classpath/36636: + * tools/gnu/classpath/tools/jar/Updater.java: + (run(Main)): Check return value of renameTo, and + copy file instead if necessary. + (copyFile(File,File)): New method to copy a file. + +2008-06-26 Andrew John Hughes <gnu_andrew@member.fsf.org> + * configure.ac: Remove AC_PROG_MKDIR_P. * examples/Makefile.am, * lib/Makefile.am, diff --git a/tools/gnu/classpath/tools/jar/Updater.java b/tools/gnu/classpath/tools/jar/Updater.java index 29586befd..a719004ed 100644 --- a/tools/gnu/classpath/tools/jar/Updater.java +++ b/tools/gnu/classpath/tools/jar/Updater.java @@ -38,6 +38,7 @@ package gnu.classpath.tools.jar; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -86,6 +87,32 @@ public class Updater } close(); - tmpFile.renameTo(parameters.archiveFile); + if (!tmpFile.renameTo(parameters.archiveFile)) + { + if (!parameters.archiveFile.delete()) + throw new IOException("Couldn't delete original JAR file " + + parameters.archiveFile); + copyFile(tmpFile, parameters.archiveFile); + tmpFile.delete(); + } + } + + private void copyFile(File sourceFile, File destFile) + throws IOException + { + BufferedInputStream source = + new BufferedInputStream(new FileInputStream(sourceFile)); + BufferedOutputStream dest = + new BufferedOutputStream(new FileOutputStream(destFile)); + int inputByte; + + while ((inputByte = source.read()) != -1) + { + dest.write(inputByte); + } + + source.close(); + dest.close(); } + } |