Skip to content

Commit

Permalink
patch for #1394
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong committed Jul 24, 2018
1 parent 0a68f98 commit 5de7ea4
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ protected boolean shouldUpdagte(File repo) throws NumberFormatException {
* initialization
*/
private void initializeRetireJsRepo(Settings settings, URL repoUrl) throws UpdateException {
File tmpFile = null;
File repoFile = null;
try {
final File dataDir = settings.getDataDirectory();
final File tmpDir = settings.getTempDirectory();
Expand All @@ -155,15 +157,26 @@ private void initializeRetireJsRepo(Settings settings, URL repoUrl) throws Updat
final HttpURLConnection conn = factory.createHttpURLConnection(repoUrl, useProxy);
final String filename = repoUrl.getFile().substring(repoUrl.getFile().lastIndexOf("/") + 1, repoUrl.getFile().length());
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
final File tmpFile = new File(tmpDir, filename);
final File repoFile = new File(dataDir, filename);
tmpFile = new File(tmpDir, filename);
repoFile = new File(dataDir, filename);
try (InputStream inputStream = conn.getInputStream();
FileOutputStream outputStream = new FileOutputStream(tmpFile)) {
IOUtils.copy(inputStream, outputStream);
}
Files.move(tmpFile.toPath(), repoFile.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
}
} catch (IOException e) {
if (e.getMessage().contains("The system cannot move the file to a different disk drive")) {
try {
LOGGER.debug("Failed to move the file; attempting copy: " + e.getMessage());
Files.copy(tmpFile.toPath(), repoFile.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
if (!tmpFile.delete()) {
tmpFile.deleteOnExit();
}
} catch (IOException ex) {
throw new UpdateException("Failed to initialize the RetireJS repo", ex);
}
}
throw new UpdateException("Failed to initialize the RetireJS repo", e);
}
}
Expand Down

0 comments on commit 5de7ea4

Please sign in to comment.