Skip to content

Commit

Permalink
Fix eirslett#670: Use Files.move instead of File.rename to move files…
Browse files Browse the repository at this point in the history
… because File.rename does not support overwriting existing files on windows
  • Loading branch information
Theoderich committed Mar 12, 2019
1 parent b45e73d commit e770282
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -151,7 +153,12 @@ private void installNodeDefault() throws InstallationException {

File destination = new File(destinationDirectory, "node");
this.logger.info("Copying node binary from {} to {}", nodeBinary, destination);
if (!nodeBinary.renameTo(destination)) {
if (destination.exists() && !destination.delete()) {
throw new InstallationException("Could not install Node: Was not allowed to delete " + destination);
}
try {
Files.move(nodeBinary.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new InstallationException("Could not install Node: Was not allowed to rename "
+ nodeBinary + " to " + destination);
}
Expand Down Expand Up @@ -219,7 +226,9 @@ private void installNodeWithNpmForWindows() throws InstallationException {

File destination = new File(destinationDirectory, "node.exe");
this.logger.info("Copying node binary from {} to {}", nodeBinary, destination);
if (!nodeBinary.renameTo(destination)) {
try {
Files.move(nodeBinary.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new InstallationException("Could not install Node: Was not allowed to rename "
+ nodeBinary + " to " + destination);
}
Expand Down

0 comments on commit e770282

Please sign in to comment.