Bug 765598 - Remove newly created MozUpdater folders in tmp on post update. r=ehsan

This commit is contained in:
Brian R. Bondy 2012-10-25 22:30:34 -04:00
parent ebe6419085
commit 398707a8f3
2 changed files with 27 additions and 0 deletions

View File

@ -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();
},
/**

View File

@ -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<nsIFile> updater;