Skip to content

Commit 9b2bbd3

Browse files
author
Andy Herrick
committedDec 17, 2019
8235667: IOUtils.copyFile() problems
Reviewed-by: rriggs, asemenyuk, almatvee
1 parent 010ac54 commit 9b2bbd3

File tree

1 file changed

+5
-19
lines changed
  • src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal

1 file changed

+5
-19
lines changed
 

‎src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java

+5-19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.nio.file.Files;
3535
import java.nio.file.Path;
3636
import java.nio.file.SimpleFileVisitor;
37+
import java.nio.file.StandardCopyOption;
3738
import java.nio.file.attribute.BasicFileAttributes;
3839
import java.util.*;
3940
import javax.xml.stream.XMLOutputFactory;
@@ -112,26 +113,11 @@ public FileVisitResult visitFile(final Path file,
112113

113114
public static void copyFile(File sourceFile, File destFile)
114115
throws IOException {
115-
destFile.getParentFile().mkdirs();
116+
Files.createDirectories(destFile.getParentFile().toPath());
116117

117-
//recreate the file as existing copy may have weird permissions
118-
destFile.delete();
119-
destFile.createNewFile();
120-
121-
try (FileChannel source = new FileInputStream(sourceFile).getChannel();
122-
FileChannel destination =
123-
new FileOutputStream(destFile).getChannel()) {
124-
destination.transferFrom(source, 0, source.size());
125-
}
126-
127-
//preserve executable bit!
128-
if (sourceFile.canExecute()) {
129-
destFile.setExecutable(true, false);
130-
}
131-
if (!sourceFile.canWrite()) {
132-
destFile.setReadOnly();
133-
}
134-
destFile.setReadable(true, false);
118+
Files.copy(sourceFile.toPath(), destFile.toPath(),
119+
StandardCopyOption.REPLACE_EXISTING,
120+
StandardCopyOption.COPY_ATTRIBUTES);
135121
}
136122

137123
// run "launcher paramfile" in the directory where paramfile is kept

0 commit comments

Comments
 (0)
Please sign in to comment.