[tbb-commits] [tor-browser/tor-browser-38.1.0esr-5.0-1] Bug 16236: Windows updater: avoid writing to the registry.
mikeperry at torproject.org
mikeperry at torproject.org
Mon Jul 27 16:01:11 UTC 2015
commit b7a65a6dcfc1963fef42b4a0d4b5013dbc8a36ad
Author: Kathy Brade <brade at pearlcrescent.com>
Date: Wed Jul 22 15:58:52 2015 -0400
Bug 16236: Windows updater: avoid writing to the registry.
Mozilla moves "in use" files that cannot be deleted during an
update to a "tobedeleted" directory and then makes a call to
MoveFileEx(..., MOVEFILE_DELAY_UNTIL_REBOOT) to request that
the file be deleted later. To avoid writing to the Windows Registry,
we simply try to remove the "tobedeleted" directory and its contents
during browser startup.
---
toolkit/mozapps/update/updater/updater.cpp | 9 ++++++++-
toolkit/xre/nsUpdateDriver.cpp | 14 ++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp
index acb610c..6e55fe2 100644
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -866,7 +866,7 @@ static int rename_file(const NS_tchar *spath, const NS_tchar *dpath,
return OK;
}
-#ifdef XP_WIN
+#if defined(XP_WIN) && !defined(TOR_BROWSER_UPDATE)
// Remove the directory pointed to by path and all of its files and
// sub-directories. If a file is in use move it to the tobedeleted directory
// and attempt to schedule removal of the file on reboot
@@ -1005,6 +1005,8 @@ static int backup_discard(const NS_tchar *path)
backup, path));
return WRITE_ERROR;
}
+
+#if !defined(TOR_BROWSER_UPDATE)
// The MoveFileEx call to remove the file on OS reboot will fail if the
// process doesn't have write access to the HKEY_LOCAL_MACHINE registry key
// but this is ok since the installer / uninstaller will delete the
@@ -1017,6 +1019,7 @@ static int backup_discard(const NS_tchar *path)
LOG(("backup_discard: failed to schedule OS reboot removal of " \
"file: " LOG_S, path));
}
+#endif
}
#else
if (rv)
@@ -2280,8 +2283,10 @@ ProcessReplaceRequest()
if (NS_taccess(deleteDir, F_OK)) {
NS_tmkdir(deleteDir, 0755);
}
+#if !defined(TOR_BROWSER_UPDATE)
remove_recursive_on_reboot(tmpDir, deleteDir);
#endif
+#endif
}
#ifdef XP_MACOSX
@@ -3360,6 +3365,7 @@ int NS_main(int argc, NS_tchar **argv)
if (!sStagedUpdate && !sReplaceRequest && _wrmdir(DELETE_DIR)) {
LOG(("NS_main: unable to remove directory: " LOG_S ", err: %d",
DELETE_DIR, errno));
+#if !defined(TOR_BROWSER_UPDATE)
// The directory probably couldn't be removed due to it containing files
// that are in use and will be removed on OS reboot. The call to remove the
// directory on OS reboot is done after the calls to remove the files so the
@@ -3376,6 +3382,7 @@ int NS_main(int argc, NS_tchar **argv)
LOG(("NS_main: failed to schedule OS reboot removal of " \
"directory: " LOG_S, DELETE_DIR));
}
+#endif
}
#endif /* XP_WIN */
diff --git a/toolkit/xre/nsUpdateDriver.cpp b/toolkit/xre/nsUpdateDriver.cpp
index ef4c5fb..085f439 100644
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -1111,6 +1111,20 @@ ProcessUpdates(nsIFile *greDir, nsIFile *appDir, nsIFile *updRootDir,
bool restart, bool isOSUpdate, nsIFile *osApplyToDir,
ProcessType *pid)
{
+#if defined(XP_WIN) && defined(TOR_BROWSER_UPDATE)
+ // Try to remove the "tobedeleted" directory which, if present, contains
+ // files that could not be removed during a previous update (e.g., DLLs
+ // that were in use and therefore locked by Windows).
+ nsCOMPtr<nsIFile> deleteDir;
+ nsresult winrv = appDir->Clone(getter_AddRefs(deleteDir));
+ if (NS_SUCCEEDED(winrv)) {
+ winrv = deleteDir->AppendNative(NS_LITERAL_CSTRING("tobedeleted"));
+ if (NS_SUCCEEDED(winrv)) {
+ winrv = deleteDir->Remove(true);
+ }
+ }
+#endif
+
nsresult rv;
nsCOMPtr<nsIFile> updatesDir;
More information about the tbb-commits
mailing list