changeset 57465:2de8425627fa

8235667: IOUtils.copyFile() problems. Reviewed-by: rriggs, asemenyuk, almatvee
author herrick
date Tue, 17 Dec 2019 08:56:52 -0500
parents 09a2449230db
children b05a7ab7ba0c
files src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java
diffstat 1 files changed, 5 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java	Tue Dec 17 20:56:53 2019 +0800
+++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java	Tue Dec 17 08:56:52 2019 -0500
@@ -34,6 +34,7 @@
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.*;
 import javax.xml.stream.XMLOutputFactory;
@@ -112,26 +113,11 @@
 
     public static void copyFile(File sourceFile, File destFile)
             throws IOException {
-        destFile.getParentFile().mkdirs();
+        Files.createDirectories(destFile.getParentFile().toPath());
 
-        //recreate the file as existing copy may have weird permissions
-        destFile.delete();
-        destFile.createNewFile();
-
-        try (FileChannel source = new FileInputStream(sourceFile).getChannel();
-            FileChannel destination =
-                    new FileOutputStream(destFile).getChannel()) {
-            destination.transferFrom(source, 0, source.size());
-        }
-
-        //preserve executable bit!
-        if (sourceFile.canExecute()) {
-            destFile.setExecutable(true, false);
-        }
-        if (!sourceFile.canWrite()) {
-            destFile.setReadOnly();
-        }
-        destFile.setReadable(true, false);
+        Files.copy(sourceFile.toPath(), destFile.toPath(),
+                   StandardCopyOption.REPLACE_EXISTING,
+                   StandardCopyOption.COPY_ATTRIBUTES);
     }
 
     // run "launcher paramfile" in the directory where paramfile is kept