Skip to content

Commit

Permalink
Merge pull request #801 from Theoderich/#670
Browse files Browse the repository at this point in the history
Fix #670: Use Files.move instead of File.rename to move files
  • Loading branch information
eirslett committed Mar 12, 2019
2 parents b45e73d + 694e8fa commit 0081f8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven-

## Changelog

### 1.7.6

* Fix #670: Plugin will no longer fail to install node.exe if node.exe already exists

### 1.5

* Revert support for the maven.frontend.failOnError flag ([#572](https://github.com/eirslett/frontend-maven-plugin/pull/572)), due to
Expand Down
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 0081f8f

Please sign in to comment.