author Kirk Steuber <>
Tue, 23 Oct 2018 21:41:04 +0000
changeset 491024 3d22697d9c23a23087190225aa201a44bc1be130
permissions -rw-r--r--
Bug 1458314 - Move the update directory to an installation specific location r=rstrong This change applies to Windows only. Firefox will need to migrate the directory from the old location to the new location. This will be done only once by setting the pref `app.update.migrated.updateDir2.<install path hash>` to `true` once migration has completed. Note: The pref name app.update.migrated.updateDir has already been used, thus the '2' suffix. It can be found in ESR24. This also removes the old handling fallback for generating the update directory path. Since xulrunner is no longer supported, this should no longer be needed. If neither the vendor nor app name are defined, it falls back to the literal string "Mozilla". The code to generate the update directory path and the installation hash have been moved to the updatecommon library. This will allow those functions to be used in Firefox, the Mozilla Maintenance Service, the Mozilla Maintenance Service Installer, and TestAUSHelper. Additionally, the function that generates the update directory path now has extra functionality. It creates the update directory, sets the permissions on it and, optionally, recursively sets the permissions on everything within. This patch adds functionality that allows Firefox to set permissions on the new update directory on write failure. It attempts to set the permissions itself and, if that fails and the maintenance service is enabled, it calls into the maintenance service to try from there. If a write fails and the permissions cannot be fixed, the user is prompted to reinstall. Differential Revision:

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#include "mozilla/UniquePtr.h"
#include "nsError.h"

#ifdef XP_WIN
#include <windows.h>
typedef WCHAR NS_tchar;
typedef char NS_tchar;

nsresult GetInstallHash(const char16_t* installPath, const char* vendor,
                        mozilla::UniquePtr<NS_tchar[]>& result,
                        bool useCompatibilityMode = false);

#ifdef XP_WIN
enum class SetPermissionsOf {
// This function does two things. It retrieves the update directory and it sets
// the permissions of the directory and, optionally, its contents.
HRESULT GetCommonUpdateDirectory(const wchar_t* installPath,
                                 const char* vendor,
                                 const char* appName,
                                 SetPermissionsOf dirPermsToSet,
                                 mozilla::UniquePtr<wchar_t[]>& result);
HRESULT GetUserUpdateDirectory(const wchar_t* installPath,
                               const char* vendor,
                               const char* appName,
                               mozilla::UniquePtr<wchar_t[]>& result);