summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-26 22:26:26 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-26 22:26:26 +0000
commit1b56c841903c989e75d6878c07524b7970fba65c (patch)
treebc78a1fa280f18f5af1ae35c7a6ca19413678ad4
parent8ebd9935d7346004b5cb935e55a963e160529bb0 (diff)
downloadclasspath-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.
-rw-r--r--ChangeLog8
-rw-r--r--tools/gnu/classpath/tools/jar/Updater.java29
2 files changed, 36 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 64252ba95..694c2ec9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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();
}
+
}