Updater: do not create a patch file in the temp dir until it is not fully downloaded (IDEA-82564) (cherry picked from commit caa341f)

This commit is contained in:
Anton Makeev
2012-04-12 14:15:54 +02:00
parent 6b5c47d817
commit cc65b1af43
@@ -613,13 +613,13 @@ public final class UpdateChecker {
OutputStream out = null;
String platform = PlatformUtils.getPlatformPrefix();
String patchFileName = ("jetbrains.patch.jar." + platform).toLowerCase();
File patchFile = new File(FileUtil.getTempDirectory(), patchFileName);
File tempFile = FileUtil.createTempFile(platform, "patch", true);
try {
connection = new URL(new URL(getPatchesUrl()), fileName).openConnection();
in = UrlConnectionUtil.getConnectionInputStreamWithException(connection, i);
out = new BufferedOutputStream(new FileOutputStream(patchFile));
out = new BufferedOutputStream(new FileOutputStream(tempFile));
i.setIndeterminate(false);
@@ -636,23 +636,16 @@ public final class UpdateChecker {
i.setText2((read / 1024) + "/" + (total / 1024) + " KB");
}
}
catch (IOException e) {
patchFile.delete();
throw e;
}
catch (ProcessCanceledException e) {
patchFile.delete();
throw e;
}
catch (Throwable e) {
patchFile.delete();
throw new RuntimeException(e);
}
finally {
if (out != null) out.close();
if (in != null) in.close();
if (connection instanceof HttpURLConnection) ((HttpURLConnection)connection).disconnect();
}
String patchFileName = ("jetbrains.patch.jar." + platform).toLowerCase();
File patchFile = new File(FileUtil.getTempDirectory(), patchFileName);
FileUtil.copy(tempFile, patchFile);
FileUtil.delete(tempFile);
}
public static Set<String> getDisabledToUpdatePlugins() {