Skip to content
Permalink
Browse files

8235667: IOUtils.copyFile() problems

Reviewed-by: rriggs, asemenyuk, almatvee
  • Loading branch information
Andy Herrick
Andy Herrick committed Dec 17, 2019
1 parent 010ac54 commit 9b2bbd3df440657101c35a2ad2756a0b74638db1
@@ -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 FileVisitResult visitFile(final Path file,

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

0 comments on commit 9b2bbd3

Please sign in to comment.
You can’t perform that action at this time.