Commit 23e8ffcb authored by Colin Pacitti's avatar Colin Pacitti Committed by Commit Bot

Implement RunApplicationInstaller() with InstallFromDMG() for mac

This has already been implemented for its Windows counterpart. It is a
simple change for mac to just pass the DMG file path to InstallFromDMG() function.

Bug: 1051763
Change-Id: Ia0858532e9c756210a1b5288bd347bd7dcd055d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065309
Commit-Queue: Colin Pacitti <copacitt@microsoft.com>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745648}
parent 14c585ae
...@@ -37,9 +37,6 @@ if (is_win || is_mac) { ...@@ -37,9 +37,6 @@ if (is_win || is_mac) {
"crash_client.h", "crash_client.h",
"crash_reporter.cc", "crash_reporter.cc",
"crash_reporter.h", "crash_reporter.h",
"installer.cc",
"installer.h",
"installer_win.cc",
"patcher.cc", "patcher.cc",
"patcher.h", "patcher.h",
"persisted_data.cc", "persisted_data.cc",
...@@ -58,7 +55,6 @@ if (is_win || is_mac) { ...@@ -58,7 +55,6 @@ if (is_win || is_mac) {
deps = [ deps = [
":version_header", ":version_header",
"//base", "//base",
"//components/crx_file",
"//components/prefs", "//components/prefs",
"//components/update_client", "//components/update_client",
"//courgette:bsdiff", "//courgette:bsdiff",
...@@ -74,6 +70,10 @@ if (is_win || is_mac) { ...@@ -74,6 +70,10 @@ if (is_win || is_mac) {
sources = [ sources = [
"configurator.cc", "configurator.cc",
"configurator.h", "configurator.h",
"installer.cc",
"installer.h",
"installer_mac.cc",
"installer_win.cc",
"update_apps.cc", "update_apps.cc",
"update_apps.h", "update_apps.h",
"update_service_in_process.cc", "update_service_in_process.cc",
...@@ -88,6 +88,7 @@ if (is_win || is_mac) { ...@@ -88,6 +88,7 @@ if (is_win || is_mac) {
"//base", "//base",
"//chrome/updater/server", "//chrome/updater/server",
"//components/crash/core/common:crash_key", "//components/crash/core/common:crash_key",
"//components/crx_file:crx_file",
"//components/prefs", "//components/prefs",
"//components/update_client", "//components/update_client",
"//components/version_info", "//components/version_info",
...@@ -100,6 +101,7 @@ if (is_win || is_mac) { ...@@ -100,6 +101,7 @@ if (is_win || is_mac) {
if (is_mac) { if (is_mac) {
deps += [ deps += [
"//chrome/updater/mac:installer_sources",
"//chrome/updater/mac:network_fetcher_sources", "//chrome/updater/mac:network_fetcher_sources",
"//chrome/updater/mac:updater_setup_sources", "//chrome/updater/mac:updater_setup_sources",
] ]
......
...@@ -228,12 +228,12 @@ base::FilePath Installer::GetCurrentInstallDir() const { ...@@ -228,12 +228,12 @@ base::FilePath Installer::GetCurrentInstallDir() const {
return GetAppInstallDir(app_id_).AppendASCII(pv_.GetString()); return GetAppInstallDir(app_id_).AppendASCII(pv_.GetString());
} }
#if !defined(OS_WIN) #if defined(OS_LINUX)
int Installer::RunApplicationInstaller(const base::FilePath& app_installer, int Installer::RunApplicationInstaller(const base::FilePath& app_installer,
const std::string& arguments) { const std::string& arguments) {
NOTREACHED(); NOTREACHED();
return -1; return -1;
} }
#endif // OS_WIN #endif // OS_LINUX
} // namespace updater } // namespace updater
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/installer.h"
#include "base/logging.h"
#include "chrome/updater/mac/installer.h"
namespace updater {
int Installer::RunApplicationInstaller(const base::FilePath& app_installer,
const std::string& arguments) {
DVLOG(1) << "Running application install from DMG";
// InstallFromDMG() returns true when it succeeds while callers of
// RunApplicationInstaller() expect a return value of 0.
return !InstallFromDMG(app_installer, arguments);
}
} // namespace updater
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_UPDATER_MAC_INSTALLER_H_ #ifndef CHROME_UPDATER_MAC_INSTALLER_H_
#define CHROME_UPDATER_MAC_INSTALLER_H_ #define CHROME_UPDATER_MAC_INSTALLER_H_
#include <string>
namespace base { namespace base {
class FilePath; class FilePath;
} }
...@@ -14,7 +16,8 @@ namespace updater { ...@@ -14,7 +16,8 @@ namespace updater {
// Mounts the DMG specified by |dmg_file_path|. The install script located at // Mounts the DMG specified by |dmg_file_path|. The install script located at
// "/.install.sh" in the mounted volume is executed, and then the DMG is // "/.install.sh" in the mounted volume is executed, and then the DMG is
// un-mounted. Returns false if mounting the dmg or executing the script failed. // un-mounted. Returns false if mounting the dmg or executing the script failed.
bool InstallFromDMG(const base::FilePath& dmg_file_path); bool InstallFromDMG(const base::FilePath& dmg_file_path,
const std::string& arguments);
} // namespace updater } // namespace updater
......
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/updater/mac/installer.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include <string>
#include <vector> #include <vector>
#include "chrome/updater/mac/installer.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
namespace updater { namespace updater {
...@@ -92,19 +94,29 @@ bool UnmountDMG(const base::FilePath& mounted_dmg_path) { ...@@ -92,19 +94,29 @@ bool UnmountDMG(const base::FilePath& mounted_dmg_path) {
} }
bool RunScript(const base::FilePath& mounted_dmg_path, bool RunScript(const base::FilePath& mounted_dmg_path,
const base::FilePath::StringPieceType script_name) { const base::FilePath::StringPieceType script_name,
const std::string& arguments) {
if (!base::PathExists(mounted_dmg_path)) { if (!base::PathExists(mounted_dmg_path)) {
DLOG(ERROR) << "File path (" << mounted_dmg_path << ") does not exist."; DLOG(ERROR) << "File path (" << mounted_dmg_path << ") does not exist.";
return false; return false;
} }
const base::FilePath script_file_path = mounted_dmg_path.Append(script_name); base::FilePath script_file_path = mounted_dmg_path.Append(script_name);
if (!base::PathExists(script_file_path)) { if (!base::PathExists(script_file_path)) {
DLOG(ERROR) << "Script file path (" << script_file_path DLOG(ERROR) << "Script file path (" << script_file_path
<< ") does not exist."; << ") does not exist.";
return false; return false;
} }
// TODO(copacitt): Improve the way we parse args for CommandLine object.
// http://crbug.com/1056818
base::CommandLine command(script_file_path); base::CommandLine command(script_file_path);
if (!arguments.empty()) {
base::CommandLine::StringVector argv =
base::SplitString(arguments, base::kWhitespaceASCII,
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
argv.insert(argv.begin(), script_file_path.value());
command = base::CommandLine(argv);
}
std::string output; std::string output;
if (!base::GetAppOutput(command, &output)) { if (!base::GetAppOutput(command, &output)) {
...@@ -117,7 +129,8 @@ bool RunScript(const base::FilePath& mounted_dmg_path, ...@@ -117,7 +129,8 @@ bool RunScript(const base::FilePath& mounted_dmg_path,
} // namespace } // namespace
bool InstallFromDMG(const base::FilePath& dmg_file_path) { bool InstallFromDMG(const base::FilePath& dmg_file_path,
const std::string& arguments) {
std::string mount_point; std::string mount_point;
if (!MountDMG(dmg_file_path, &mount_point)) if (!MountDMG(dmg_file_path, &mount_point))
return false; return false;
...@@ -126,9 +139,8 @@ bool InstallFromDMG(const base::FilePath& dmg_file_path) { ...@@ -126,9 +139,8 @@ bool InstallFromDMG(const base::FilePath& dmg_file_path) {
DLOG(ERROR) << "No mount point."; DLOG(ERROR) << "No mount point.";
return false; return false;
} }
const base::FilePath mounted_dmg_path = base::FilePath(mount_point); const base::FilePath mounted_dmg_path = base::FilePath(mount_point);
bool result = RunScript(mounted_dmg_path, ".install.sh"); bool result = RunScript(mounted_dmg_path, ".install.sh", arguments);
if (!UnmountDMG(mounted_dmg_path)) if (!UnmountDMG(mounted_dmg_path))
DLOG(WARNING) << "Could not unmount the DMG: " << mounted_dmg_path; DLOG(WARNING) << "Could not unmount the DMG: " << mounted_dmg_path;
......
...@@ -27,7 +27,20 @@ TEST_F(ChromeUpdaterMacSetupTest, InstallFromDMG) { ...@@ -27,7 +27,20 @@ TEST_F(ChromeUpdaterMacSetupTest, InstallFromDMG) {
const base::FilePath dmg_file_path = const base::FilePath dmg_file_path =
test_data_dir.Append(FILE_PATH_LITERAL("updater_setup_test_dmg.dmg")); test_data_dir.Append(FILE_PATH_LITERAL("updater_setup_test_dmg.dmg"));
ASSERT_TRUE(base::PathExists(dmg_file_path)); ASSERT_TRUE(base::PathExists(dmg_file_path));
ASSERT_TRUE(updater::InstallFromDMG(dmg_file_path)); ASSERT_TRUE(updater::InstallFromDMG(dmg_file_path, ""));
}
TEST_F(ChromeUpdaterMacSetupTest, InstallFromDMGWithArgs) {
// Get the path to the test file.
base::FilePath test_data_dir;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("updater"));
ASSERT_TRUE(base::PathExists(test_data_dir));
// Get the DMG path and check that it exists.
const base::FilePath dmg_file_path =
test_data_dir.Append(FILE_PATH_LITERAL("updater_setup_test_dmg.dmg"));
ASSERT_TRUE(base::PathExists(dmg_file_path));
ASSERT_TRUE(updater::InstallFromDMG(dmg_file_path, "-arg1 -arg2"));
} }
} // namespace updater_setup } // namespace updater_setup
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment