From 36d06c5988a2c8ed94edbacbca6db2a01daaaa66 Mon Sep 17 00:00:00 2001
From: Jeff Morgan <jmorganca@gmail.com>
Date: Tue, 9 Dec 2014 22:58:15 -0800
Subject: [PATCH] Fixing sync bug where deleted container would re-appear after
 deletion

---
 meteor/client/lib/apputil.js |  4 ++--
 meteor/client/main.js        | 30 +++++++++++++++---------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/meteor/client/lib/apputil.js b/meteor/client/lib/apputil.js
index e33946e8aa..ffec535e41 100644
--- a/meteor/client/lib/apputil.js
+++ b/meteor/client/lib/apputil.js
@@ -67,10 +67,10 @@ AppUtil.stop = function (appId) {
 AppUtil.remove = function (appId) {
   var app = Apps.findOne(appId);
   if (app.docker) {
-    Apps.remove({_id: appId});
     Docker.removeContainer(app.docker.Id, function (err) {
       var appPath = path.join(Util.KITE_PATH, app.name);
       Util.deleteFolder(appPath);
+      Apps.remove({_id: appId});
     });
   } else {
     Apps.remove({_id: appId});
@@ -153,7 +153,7 @@ AppUtil.sync = function (callback) {
     var diffApps = _.difference(guiIds, containerIds);
     _.each(diffApps, function (appContainerId) {
       var app = Apps.findOne({'docker.Id': appContainerId});
-      if (app) {
+      if (app && app.status !== 'STARTING') {
         AppUtil.remove(app._id);
       }
     });
diff --git a/meteor/client/main.js b/meteor/client/main.js
index 9919c23873..532a50bc28 100755
--- a/meteor/client/main.js
+++ b/meteor/client/main.js
@@ -221,24 +221,24 @@ updateBoot2DockerUtilization = function (callback) {
   });
 };
 
+
+
 startUpdatingBoot2DockerUtilization = function () {
-  updateBoot2DockerUtilization(function (err) {
-    if (err) {console.log(err);}
-    Meteor.setTimeout(startUpdatingBoot2DockerUtilization, 2000);
-  });
+  updateBoot2DockerUtilization(function (err) { if (err) {console.log(err);} });
+  Meteor.setTimeout(startUpdatingBoot2DockerUtilization, 2000);
 };
 
 startSyncingAppState = function () {
-  try {
-    ImageUtil.sync(function (err) {
-      if (err) {throw err;}
-      AppUtil.sync(function (err) {
-        if (err) {throw err;}
-        Meteor.setTimeout(startSyncingAppState, 2000);
-      });
+  console.log('app');
+  ImageUtil.sync(function (err) {
+    if (err) {
+      console.log(err);
+    }
+    AppUtil.sync(function (err) {
+      if (err) {
+        console.log(err);
+      }
     });
-  } catch (err) {
-    console.log(err);
-    Meteor.setTimeout(startSyncingAppState, 2000);
-  }
+  });
+  Meteor.setTimeout(startSyncingAppState, 2000);
 };