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

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

Issue 8299008: Errors while deleting old version dirs no longer cause them to grow in odd ways. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addresses nits Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/delete_tree_work_item.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // with ERROR_SHARING_VIOLATION if the file exists and is in-use. 441 // with ERROR_SHARING_VIOLATION if the file exists and is in-use.
442 return !base::win::ScopedHandle(CreateFile(file.value().c_str(), 442 return !base::win::ScopedHandle(CreateFile(file.value().c_str(),
443 GENERIC_WRITE, 0, NULL, 443 GENERIC_WRITE, 0, NULL,
444 OPEN_EXISTING, 0, 0)).IsValid(); 444 OPEN_EXISTING, 0, 0)).IsValid();
445 } 445 }
446 446
447 void InstallerState::RemoveOldVersionDirectories( 447 void InstallerState::RemoveOldVersionDirectories(
448 const Version& new_version, 448 const Version& new_version,
449 Version* existing_version, 449 Version* existing_version,
450 const FilePath& temp_path) const { 450 const FilePath& temp_path) const {
451 scoped_ptr<Version> version;
452 std::vector<FilePath> key_files;
453 scoped_ptr<WorkItem> item;
454
455 // Try to delete all directories whose versions are lower than latest_version
456 // and not equal to the existing version (opv).
451 file_util::FileEnumerator version_enum(target_path(), false, 457 file_util::FileEnumerator version_enum(target_path(), false,
452 file_util::FileEnumerator::DIRECTORIES); 458 file_util::FileEnumerator::DIRECTORIES);
453 scoped_ptr<Version> version; 459 for (FilePath next_version = version_enum.Next(); !next_version.empty();
454 std::vector<FilePath> key_files; 460 next_version = version_enum.Next()) {
461 FilePath dir_name(next_version.BaseName());
462 version.reset(Version::GetVersionFromString(WideToASCII(dir_name.value())));
463 // Delete the version folder if it is less than the new version and not
464 // equal to the old version (if we have an old version).
465 if (version.get() &&
466 version->CompareTo(new_version) < 0 &&
467 (existing_version == NULL || !version->Equals(*existing_version))) {
468 // Collect the key files (relative to the version dir) for all products.
469 key_files.clear();
470 std::for_each(products_.begin(), products_.end(),
471 std::bind2nd(std::mem_fun(&Product::AddKeyFiles),
472 &key_files));
473 // Make the key_paths absolute.
474 const std::vector<FilePath>::iterator end = key_files.end();
475 for (std::vector<FilePath>::iterator scan = key_files.begin();
476 scan != end; ++scan) {
477 *scan = next_version.Append(*scan);
478 }
455 479
456 // We try to delete all directories whose versions are lower than 480 VLOG(1) << "Deleting old version directory: " << next_version.value();
457 // latest_version.
458 FilePath next_version = version_enum.Next();
459 while (!next_version.empty()) {
460 file_util::FileEnumerator::FindInfo find_data = {0};
461 version_enum.GetFindInfo(&find_data);
462 VLOG(1) << "directory found: " << find_data.cFileName;
463 version.reset(Version::GetVersionFromString(
464 WideToASCII(find_data.cFileName)));
465 if (version.get()) {
466 // Delete the version folder if it is less than the new version and not
467 // equal to the old version (if we have an old version).
468 if (version->CompareTo(new_version) < 0 &&
469 (existing_version == NULL ||
470 version->CompareTo(*existing_version) != 0)) {
471 key_files.clear();
472 std::for_each(products_.begin(), products_.end(),
473 std::bind2nd(std::mem_fun(&Product::AddKeyFiles),
474 &key_files));
475 const std::vector<FilePath>::iterator end = key_files.end();
476 for (std::vector<FilePath>::iterator scan = key_files.begin();
477 scan != end; ++scan) {
478 *scan = next_version.Append(*scan);
479 }
480 481
481 VLOG(1) << "Deleting directory: " << next_version.value(); 482 item.reset(WorkItem::CreateDeleteTreeWorkItem(next_version, temp_path,
482 483 key_files));
483 scoped_ptr<WorkItem> item( 484 item->set_ignore_failure(true);
484 WorkItem::CreateDeleteTreeWorkItem(next_version, temp_path, 485 item->Do();
485 key_files));
486 if (!item->Do()) {
487 LOG(ERROR) << "Failed to delete old version directory: "
488 << next_version.value();
489 item->Rollback();
490 }
491 }
492 } 486 }
493
494 next_version = version_enum.Next();
495 } 487 }
496 } 488 }
497 489
498 void InstallerState::AddComDllList(std::vector<FilePath>* com_dll_list) const { 490 void InstallerState::AddComDllList(std::vector<FilePath>* com_dll_list) const {
499 std::for_each(products_.begin(), products_.end(), 491 std::for_each(products_.begin(), products_.end(),
500 std::bind2nd(std::mem_fun(&Product::AddComDllList), 492 std::bind2nd(std::mem_fun(&Product::AddComDllList),
501 com_dll_list)); 493 com_dll_list));
502 } 494 }
503 495
504 bool InstallerState::SetChannelFlags(bool set, 496 bool InstallerState::SetChannelFlags(bool set,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (is_multi_install()) { 598 if (is_multi_install()) {
607 InstallUtil::AddInstallerResultItems( 599 InstallUtil::AddInstallerResultItems(
608 system_install, multi_package_binaries_distribution()->GetStateKey(), 600 system_install, multi_package_binaries_distribution()->GetStateKey(),
609 status, string_resource_id, launch_cmd, install_list.get()); 601 status, string_resource_id, launch_cmd, install_list.get());
610 } 602 }
611 if (!install_list->Do()) 603 if (!install_list->Do())
612 LOG(ERROR) << "Failed to record installer error information in registry."; 604 LOG(ERROR) << "Failed to record installer error information in registry.";
613 } 605 }
614 606
615 } // namespace installer 607 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/delete_tree_work_item.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698