]> source.dussan.org Git - jgit.git/commitdiff
Do not perform character translation on copies in patches 80/8880/2
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 27 Nov 2012 07:51:31 +0000 (08:51 +0100)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 27 Dec 2012 16:29:13 +0000 (17:29 +0100)
Translation is unnecessary and risks damaging the file. Also
ensure that we close the file if an I/O error occurs.

Change-Id: Ieae6eb941fdeaa61f2611f4cd14dd39117aa12f9

org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java

index 2bda76c323d7c8ad826f76f3805379fc81f48595..2147a2e5c4084edc3e4c2a22ff33b242ec3aead0 100644 (file)
@@ -43,6 +43,7 @@
 package org.eclipse.jgit.api;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -147,10 +148,14 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
                                case COPY:
                                        f = getFile(fh.getOldPath(), false);
                                        byte[] bs = IO.readFully(f);
-                                       FileWriter fw = new FileWriter(getFile(fh.getNewPath(),
+                                       FileOutputStream fos = new FileOutputStream(getFile(
+                                                       fh.getNewPath(),
                                                        true));
-                                       fw.write(new String(bs));
-                                       fw.close();
+                                       try {
+                                               fos.write(bs);
+                                       } finally {
+                                               fos.close();
+                                       }
                                }
                                r.addUpdatedFile(f);
                        }