From ab8d887759ba48ce856885f11ffb6afe837ca933 Mon Sep 17 00:00:00 2001 From: "waffles@chromium.org" Date: Fri, 20 Sep 2013 04:17:59 +0000 Subject: [PATCH] Delete the installation directory if the installation fails. This prevents us from leaving a partially-installed directory on the disk, which can confuse future Chrome start-ups. BUG=245318 Review URL: https://chromiumcodereview.appspot.com/23684052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224280 0039d316-1c4b-4281-b951-d872f2087c98 --- .../default_component_installer.cc | 26 ++++++++++++++++------ .../default_component_installer.h | 3 +++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/chrome/browser/component_updater/default_component_installer.cc b/chrome/browser/component_updater/default_component_installer.cc index 9c7e6e02eda5..b610f2ee4267 100644 --- a/chrome/browser/component_updater/default_component_installer.cc +++ b/chrome/browser/component_updater/default_component_installer.cc @@ -43,6 +43,19 @@ void DefaultComponentInstaller::OnUpdateError(int error) { NOTREACHED() << "Component update error: " << error; } +bool DefaultComponentInstaller::InstallHelper( + const base::DictionaryValue& manifest, + const base::FilePath& unpack_path, + const base::FilePath& install_path) { + if (!base::Move(unpack_path, install_path)) + return false; + if (!installer_traits_->OnCustomInstall(manifest, install_path)) + return false; + if (!installer_traits_->VerifyInstallation(install_path)) + return false; + return true; +} + bool DefaultComponentInstaller::Install(const base::DictionaryValue& manifest, const base::FilePath& unpack_path) { std::string manifest_version; @@ -54,13 +67,12 @@ bool DefaultComponentInstaller::Install(const base::DictionaryValue& manifest, return false; base::FilePath install_path = installer_traits_->GetBaseDirectory().AppendASCII(version.GetString()); - if (base::PathExists(install_path)) - return false; - if (!base::Move(unpack_path, install_path)) - return false; - if (!installer_traits_->OnCustomInstall(manifest, install_path)) - return false; - if (!installer_traits_->VerifyInstallation(install_path)) { + if (base::PathExists(install_path)) { + if (!base::DeleteFile(install_path, true)) + return false; + } + if (!InstallHelper(manifest, unpack_path, install_path)) { + base::DeleteFile(install_path, true); return false; } current_version_ = version; diff --git a/chrome/browser/component_updater/default_component_installer.h b/chrome/browser/component_updater/default_component_installer.h index 037438ef70f1..10bdcc3bbfe4 100644 --- a/chrome/browser/component_updater/default_component_installer.h +++ b/chrome/browser/component_updater/default_component_installer.h @@ -87,6 +87,9 @@ class DefaultComponentInstaller : public ComponentInstaller { private: base::FilePath GetInstallDirectory(); + bool InstallHelper(const base::DictionaryValue& manifest, + const base::FilePath& unpack_path, + const base::FilePath& install_path); void StartRegistration(ComponentUpdateService* cus); void FinishRegistration(ComponentUpdateService* cus); -- 2.11.4.GIT