Skip to content

Commit

Permalink
Issue eirslett#794
Browse files Browse the repository at this point in the history
The node, npm and yarn installer deletes corrupted archive and destination directory in case if the downloading was interrupted (causes EOFException when extracted).
  • Loading branch information
seregamorph committed Apr 16, 2019
1 parent 0081f8f commit 1a6ebf8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven-
### 1.7.6

* Fix #670: Plugin will no longer fail to install node.exe if node.exe already exists
* Fix #794: Plugin will self-repair if previous node/npm/yarn archive download was interrupted

### 1.5

Expand Down
@@ -1,5 +1,6 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -139,12 +140,28 @@ private void installNpm() throws InstallationException {
this.logger.warn("Failed to delete existing NPM installation.");
}

extractFile(archive, nodeModulesDirectory);
File packageDirectory = new File(nodeModulesDirectory, "package");
try {
extractFile(archive, nodeModulesDirectory);
} catch (ArchiveExtractionException e) {
if (e.getCause() instanceof EOFException) {
// https://github.com/eirslett/frontend-maven-plugin/issues/794
// The downloading was probably interrupted and archive file is incomplete:
// delete it to retry from scratch
this.logger.error("The archive file {} is corrupted and will be deleted. "
+ "Please try the build again.", archive.getPath());
archive.delete();
if (packageDirectory.exists()) {
FileUtils.deleteDirectory(packageDirectory);
}
}

throw e;
}

// handles difference between old and new download root (nodejs.org/dist/npm and
// registry.npmjs.org)
// see https://github.com/eirslett/frontend-maven-plugin/issues/65#issuecomment-52024254
File packageDirectory = new File(nodeModulesDirectory, "package");
if (packageDirectory.exists() && !npmDirectory.exists()) {
if (!packageDirectory.renameTo(npmDirectory)) {
this.logger.warn("Cannot rename NPM directory, making a copy.");
Expand Down
@@ -1,5 +1,6 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -140,7 +141,21 @@ private void installNodeDefault() throws InstallationException {

downloadFileIfMissing(downloadUrl, archive, this.userName, this.password);

extractFile(archive, tmpDirectory);
try {
extractFile(archive, tmpDirectory);
} catch (ArchiveExtractionException e) {
if (e.getCause() instanceof EOFException) {
// https://github.com/eirslett/frontend-maven-plugin/issues/794
// The downloading was probably interrupted and archive file is incomplete:
// delete it to retry from scratch
this.logger.error("The archive file {} is corrupted and will be deleted. "
+ "Please try the build again.", archive.getPath());
archive.delete();
FileUtils.deleteDirectory(tmpDirectory);
}

throw e;
}

// Search for the node binary
File nodeBinary =
Expand Down
@@ -1,5 +1,6 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -122,7 +123,23 @@ private void installYarn() throws InstallationException {
logger.warn("Failed to delete existing Yarn installation.");
}

extractFile(archive, installDirectory);
try {
extractFile(archive, installDirectory);
} catch (ArchiveExtractionException e) {
if (e.getCause() instanceof EOFException) {
// https://github.com/eirslett/frontend-maven-plugin/issues/794
// The downloading was probably interrupted and archive file is incomplete:
// delete it to retry from scratch
this.logger.error("The archive file {} is corrupted and will be deleted. "
+ "Please try the build again.", archive.getPath());
archive.delete();
if (installDirectory.exists()) {
FileUtils.deleteDirectory(installDirectory);
}
}

throw e;
}

ensureCorrectYarnRootDirectory(installDirectory, yarnVersion);

Expand Down

0 comments on commit 1a6ebf8

Please sign in to comment.