Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Unified Diff: editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java

Issue 561293004: check vm and dartium before update (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java
diff --git a/editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java b/editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java
index 7568b0701a053af3bd2fc3e8993fd862f13cb16a..5476a9cd07ac73a3040a01d5afb3acc41e625717 100644
--- a/editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java
+++ b/editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java
@@ -13,6 +13,7 @@
*/
package com.google.dart.tools.update.core.internal.jobs;
+import com.google.dart.engine.sdk.DirectoryBasedDartSdk;
import com.google.dart.tools.core.DartCore;
import com.google.dart.tools.core.dart2js.ProcessRunner;
import com.google.dart.tools.core.model.DartSdkManager;
@@ -52,6 +53,45 @@ import java.util.List;
*/
public class InstallUpdateAction extends Action {
+ /**
+ * Internal representation of an executable file that needs to be renamed before update and
+ * cleaned up after update.
+ */
+ private static class Executable {
+ private final String name;
+ private final File executable;
+ private final File oldExecutable;
+
+ Executable(String name, File executable) {
+ this.name = name;
+ this.executable = executable;
+ this.oldExecutable = new File(executable.getAbsolutePath() + ".old");
+ }
+
+ boolean deleteOld() {
+ return !oldExecutable.exists() || oldExecutable.delete();
+ }
+
+ String getExistingProcessMessage() {
+ return "Update complete, but existing " + name + " process still running.\n\n"
+ + oldExecutable.getAbsolutePath();
+ }
+
+ String getRenameFailedMessage() {
+ return "Could not update " + name + ". Please terminate any running\n" + name
+ + " processes, check the file permissions, and try again.\n\n"
+ + executable.getAbsolutePath() + "\n" + oldExecutable.getAbsolutePath();
+ }
+
+ boolean rename() {
+ return deleteOld() && executable.renameTo(oldExecutable);
+ }
+
+ void restore() {
+ oldExecutable.renameTo(executable);
+ }
+ }
+
private static class RetryUpdateDialog extends MessageDialog {
public RetryUpdateDialog(Shell parentShell) {
@@ -146,8 +186,38 @@ public class InstallUpdateAction extends Action {
}
}
+ DirectoryBasedDartSdk sdk = DartSdkManager.getManager().getSdk();
+ Executable[] executables = new Executable[] {
+ new Executable("Dart VM", sdk.getVmExecutable()),
+ new Executable("Dartium", sdk.getDartiumExecutable())};
+ int index = 0;
+ while (index < executables.length) {
+ if (!executables[index].rename()) {
+ Executable failedRename = executables[index];
+ --index;
+ while (index >= 0) {
+ executables[index].restore();
+ --index;
+ }
+ MessageDialog.openError(
+ getShell(),
+ UpdateJobMessages.InstallUpdateAction_errorTitle,
+ failedRename.getRenameFailedMessage());
+ return;
+ }
+ ++index;
+ }
+
try {
if (applyUpdate()) {
+ for (Executable executable : executables) {
+ if (!executable.deleteOld()) {
+ MessageDialog.openError(
+ getShell(),
+ UpdateJobMessages.InstallUpdateAction_errorTitle,
+ executable.getExistingProcessMessage());
+ }
+ }
restart();
}
} catch (Throwable th) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698