Mac v2 signing - Bug 1072554 - Remove update directories when running xpcshell tests. r=spohl
authorRobert Strong <robert.bugzilla@gmail.com>
Mon, 29 Sep 2014 11:52:59 -0700
changeset 207685 4f0a10f05200de7a59c4f4a0f94c68831ad702cb
parent 207684 4932dbbc1cc8bbcff91175c7bb49f00cafb627bc
child 207686 28ae112eba8d158a006f5e2f1f4852f4c4e2f093
push id9046
push userrstrong@mozilla.com
push dateMon, 29 Sep 2014 18:53:28 +0000
treeherderfx-team@c5ba012a6944 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1072554
milestone35.0a1
Mac v2 signing - Bug 1072554 - Remove update directories when running xpcshell tests. r=spohl
toolkit/mozapps/update/tests/unit_aus_update/head_update.js
--- a/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
+++ b/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
@@ -937,29 +937,49 @@ function cleanupTestCommon() {
       if (key.hasValue(appDir.path)) {
         key.removeValue(appDir.path);
       }
     } catch (e) {
     }
   }
 
   // The updates directory is located outside of the application directory on
-  // Windows and Mac so it also needs to be removed.
+  // Windows and Mac OS X so it also needs to be removed.
   if (IS_WIN || IS_MACOSX) {
     let updatesDir = getMockUpdRootD();
     // Try to remove the directory used to apply updates. Since the test has
     // already finished this is non-fatal for the test.
     if (updatesDir.exists()) {
       logTestInfo("attempting to remove directory. Path: " + updatesDir.path);
       try {
         removeDirRecursive(updatesDir);
       } catch (e) {
         logTestInfo("non-fatal error removing directory. Path: " +
                     updatesDir.path + ", Exception: " + e);
       }
+      if (IS_MACOSX) {
+        let updatesRootDir = gUpdatesRootDir.clone();
+        while (updatesRootDir.path != updatesDir.path) {
+          if (updatesDir.exists()) {
+            logTestInfo("attempting to remove directory. Path: " +
+                        updatesDir.path);
+            try {
+              // Try to remove the directory without the recursive flag set
+              // since the top level directory has already had its contents
+              // removed and the parent directory might still be used by a
+              // different test.
+              updatesDir.remove(false);
+            } catch (e) {
+              logTestInfo("non-fatal error removing directory. Path: " +
+                          updatesDir.path + ", Exception: " + e);
+            }
+          }
+          updatesDir = updatesDir.parent;
+        }
+      }
     }
   }
 
   let applyDir = getApplyDirFile(null, true).parent;
 
   // Try to remove the directory used to apply updates. Since the test has
   // already finished this is non-fatal for the test.
   if (applyDir.exists()) {
@@ -1351,48 +1371,45 @@ function getMockUpdRootD() {
 
   let updatesDir = AUS_Cc["@mozilla.org/file/local;1"].
                    createInstance(AUS_Ci.nsILocalFile);
   updatesDir.initWithPath(localAppDataDir.path + "\\" + relPathUpdates);
   logTestInfo("returning UpdRootD Path: " + updatesDir.path);
   return updatesDir;
 }
 #elif XP_MACOSX
+XPCOMUtils.defineLazyGetter(this, "gUpdatesRootDir",
+                            function test_gUpdatesRootDir() {
+  let dir = Services.dirsvc.get("ULibDir", AUS_Ci.nsILocalFile);
+  dir.append("Caches");
+  if (MOZ_APP_VENDOR || MOZ_APP_BASENAME) {
+    dir.append(MOZ_APP_VENDOR ? MOZ_APP_VENDOR : MOZ_APP_BASENAME);
+  } else {
+    dir.append("Mozilla");
+  }
+  dir.append(DIR_UPDATES);
+  return dir;
+});
+
 /**
  * Helper function for getting the update root directory used by the tests. This
  * returns the same directory as returned by nsXREDirProvider::GetUpdateRootDir
  * in nsXREDirProvider.cpp so an application will be able to find the update
  * when running a test that launches the application.
  */
 function getMockUpdRootD() {
-  let userLibDir = Services.dirsvc.get("ULibDir", AUS_Ci.nsILocalFile);
   let appDir = Services.dirsvc.get(XRE_EXECUTABLE_FILE, AUS_Ci.nsIFile).
                parent.parent.parent;
   let appDirPath = appDir.path;
   appDirPath = appDirPath.substr(0, appDirPath.length - 4);
 
-  let relPathUpdates = "";
-  if (MOZ_APP_VENDOR || MOZ_APP_BASENAME) {
-    relPathUpdates += (MOZ_APP_VENDOR ? MOZ_APP_VENDOR : MOZ_APP_BASENAME) +
-                      "/" + DIR_UPDATES + appDirPath;
-  }
-
-  if (!relPathUpdates) {
-    if (MOZ_APP_VENDOR && MOZ_APP_BASENAME) {
-      relPathUpdates += MOZ_APP_VENDOR + "/" + MOZ_APP_BASENAME;
-    } else {
-      relPathUpdates += MOZ_APP_BASENAME;
-    }
-    relPathUpdates += "/" + MOZ_APP_NAME;
-  }
-
+  let pathUpdates = gUpdatesRootDir.path + appDirPath;
   let updatesDir = AUS_Cc["@mozilla.org/file/local;1"].
                    createInstance(AUS_Ci.nsILocalFile);
-
-  updatesDir.initWithPath(userLibDir.path + "/Caches/" + relPathUpdates);
+  updatesDir.initWithPath(pathUpdates);
   logTestInfo("returning UpdRootD Path: " + updatesDir.path);
   return updatesDir;
 }
 #else
 /**
  * Helper function for getting the update root directory used by the tests. This
  * returns the same directory as returned by nsXREDirProvider::GetUpdateRootDir
  * in nsXREDirProvider.cpp so an application will be able to find the update