From 398707a8f37b1e0781bb91b42e71a973193fba6b Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Thu, 25 Oct 2012 22:30:34 -0400 Subject: [PATCH] Bug 765598 - Remove newly created MozUpdater folders in tmp on post update. r=ehsan --- toolkit/mozapps/update/nsUpdateService.js | 23 +++++++++++++++++++++++ toolkit/xre/nsUpdateDriver.cpp | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/toolkit/mozapps/update/nsUpdateService.js b/toolkit/mozapps/update/nsUpdateService.js index 0e77b6ce7246..000891410040 100644 --- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -751,6 +751,26 @@ function writeVersionFile(dir, version) { writeStringToFile(versionFile, version); } +/** + * Removes the MozUpdater folders that bgupdates/staged updates creates. + */ +function cleanUpMozUpdaterDirs() { + try { + var tmpDir = Components.classes["@mozilla.org/file/directory_service;1"]. + getService(Components.interfaces.nsIProperties). + get("TmpD", Components.interfaces.nsIFile); + // All temp unique subfolders are inside MozUpdater, delete it recursively. + var mozUpdaterDir = tmpDir.clone(); + mozUpdaterDir.append("MozUpdater"); + if (mozUpdaterDir.exists()) { + LOG("cleanUpMozUpdaterDirs - Cleaning MozUpdater folder"); + mozUpdaterDir.remove(true); + } + } catch (e) { + LOG("cleanUpMozUpdaterDirs - Exception: " + e); + } +} + /** * Removes the contents of the Updates Directory * @@ -1697,6 +1717,9 @@ UpdateService.prototype = { prompter.showUpdateError(update); } + + // Now trash the MozUpdater folders which staged/bgupdates uses. + cleanUpMozUpdaterDirs(); }, /** diff --git a/toolkit/xre/nsUpdateDriver.cpp b/toolkit/xre/nsUpdateDriver.cpp index c6752b7d1c80..f945e24d7d56 100644 --- a/toolkit/xre/nsUpdateDriver.cpp +++ b/toolkit/xre/nsUpdateDriver.cpp @@ -376,7 +376,11 @@ SwitchToUpdatedApp(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile, // updater binary in the OS temporary location which we cannot write to. // Note that we don't check for errors here, as if this directory can't // be created, the following CopyUpdaterIntoUpdateDir call will fail. + // We create the unique directory inside a subfolder of MozUpdater instead + // of directly in the temp directory so we can efficiently delete everything + // after updates. tmpDir->Append(NS_LITERAL_STRING("MozUpdater")); + tmpDir->Append(NS_LITERAL_STRING("bgupdate")); tmpDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0755); nsCOMPtr updater;