Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: chrome/installer/util/installer_state.cc

Issue 1764053002: Revert of Delete old files after an update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/util/installer_state.h" 5 #include "chrome/installer/util/installer_state.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_version_info.h"
15 #include "base/files/file_enumerator.h"
14 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/macros.h" 18 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "base/win/registry.h" 22 #include "base/win/registry.h"
21 #include "base/win/scoped_handle.h" 23 #include "base/win/scoped_handle.h"
22 #include "chrome/installer/util/delete_tree_work_item.h" 24 #include "chrome/installer/util/delete_tree_work_item.h"
23 #include "chrome/installer/util/helper.h" 25 #include "chrome/installer/util/helper.h"
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 for (int i = 0; i < NUM_BINARIES; ++i) { 507 for (int i = 0; i < NUM_BINARIES; ++i) {
506 if (!(file_bits & (1U << i))) 508 if (!(file_bits & (1U << i)))
507 continue; 509 continue;
508 base::FilePath file(directory.Append(kBinaryFileNames[i])); 510 base::FilePath file(directory.Append(kBinaryFileNames[i]));
509 if (base::PathExists(file) && IsFileInUse(file)) 511 if (base::PathExists(file) && IsFileInUse(file))
510 return true; 512 return true;
511 } 513 }
512 return false; 514 return false;
513 } 515 }
514 516
517 void InstallerState::GetExistingExeVersions(
518 std::set<std::string>* existing_versions) const {
519
520 static const wchar_t* const kChromeFilenames[] = {
521 installer::kChromeExe,
522 installer::kChromeNewExe,
523 installer::kChromeOldExe,
524 };
525
526 for (size_t i = 0; i < arraysize(kChromeFilenames); ++i) {
527 base::FilePath chrome_exe(target_path().Append(kChromeFilenames[i]));
528 scoped_ptr<FileVersionInfo> file_version_info(
529 FileVersionInfo::CreateFileVersionInfo(chrome_exe));
530 if (file_version_info) {
531 base::string16 version_string = file_version_info->file_version();
532 if (!version_string.empty() && base::IsStringASCII(version_string))
533 existing_versions->insert(base::UTF16ToASCII(version_string));
534 }
535 }
536 }
537
538 void InstallerState::RemoveOldVersionDirectories(
539 const Version& new_version,
540 Version* existing_version,
541 const base::FilePath& temp_path) const {
542 Version version;
543 scoped_ptr<WorkItem> item;
544
545 std::set<std::string> existing_version_strings;
546 existing_version_strings.insert(new_version.GetString());
547 if (existing_version)
548 existing_version_strings.insert(existing_version->GetString());
549
550 // Make sure not to delete any version dir that is "referenced" by an existing
551 // Chrome executable.
552 GetExistingExeVersions(&existing_version_strings);
553
554 // Try to delete all directories that are not in the set we care to keep.
555 base::FileEnumerator version_enum(target_path(), false,
556 base::FileEnumerator::DIRECTORIES);
557 for (base::FilePath next_version = version_enum.Next(); !next_version.empty();
558 next_version = version_enum.Next()) {
559 base::FilePath dir_name(next_version.BaseName());
560 version = Version(base::UTF16ToASCII(dir_name.value()));
561 // Delete the version folder if it is less than the new version and not
562 // equal to the old version (if we have an old version).
563 if (version.IsValid() &&
564 existing_version_strings.count(version.GetString()) == 0) {
565 // Note: temporarily log old version deletion at ERROR level to make it
566 // more likely we see this in the installer log.
567 LOG(ERROR) << "Deleting old version directory: " << next_version.value();
568
569 // Attempt to recursively delete the old version dir.
570 bool delete_succeeded = base::DeleteFile(next_version, true);
571
572 // Note: temporarily log old version deletion at ERROR level to make it
573 // more likely we see this in the installer log.
574 LOG_IF(ERROR, !delete_succeeded)
575 << "Failed to delete old version directory: " << next_version.value();
576 }
577 }
578 }
579
515 void InstallerState::AddComDllList( 580 void InstallerState::AddComDllList(
516 std::vector<base::FilePath>* com_dll_list) const { 581 std::vector<base::FilePath>* com_dll_list) const {
517 for (auto* product : products_) 582 for (auto* product : products_)
518 product->AddComDllList(com_dll_list); 583 product->AddComDllList(com_dll_list);
519 } 584 }
520 585
521 void InstallerState::UpdateStage(installer::InstallerStage stage) const { 586 void InstallerState::UpdateStage(installer::InstallerStage stage) const {
522 InstallUtil::UpdateInstallerStage(system_install(), state_key_, stage); 587 InstallUtil::UpdateInstallerStage(system_install(), state_key_, stage);
523 } 588 }
524 589
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 690 }
626 if (!install_list->Do()) 691 if (!install_list->Do())
627 LOG(ERROR) << "Failed to record installer error information in registry."; 692 LOG(ERROR) << "Failed to record installer error information in registry.";
628 } 693 }
629 694
630 bool InstallerState::RequiresActiveSetup() const { 695 bool InstallerState::RequiresActiveSetup() const {
631 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); 696 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER);
632 } 697 }
633 698
634 } // namespace installer 699 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/installer_state.h ('k') | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698