diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2008-06-26 22:26:26 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2008-06-26 22:26:26 +0000 |
commit | 1b56c841903c989e75d6878c07524b7970fba65c (patch) | |
tree | bc78a1fa280f18f5af1ae35c7a6ca19413678ad4 /tools/gnu | |
parent | 8ebd9935d7346004b5cb935e55a963e160529bb0 (diff) | |
download | classpath-1b56c841903c989e75d6878c07524b7970fba65c.tar.gz |
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.
Diffstat (limited to 'tools/gnu')
-rw-r--r-- | tools/gnu/classpath/tools/jar/Updater.java | 29 |
1 files changed, 28 insertions, 1 deletions
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(); } + } |