OLD | NEW |
---|---|
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 Loading... | |
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 VLOG(1) << "Directory found: " << dir_name.value(); | |
robertshield
2011/10/14 21:28:35
Is this log useful to folk reading the log file?
grt (UTC plus 2)
2011/10/14 22:55:25
Hmm. Not so much. Removed.
| |
463 version.reset(Version::GetVersionFromString(WideToASCII(dir_name.value()))); | |
464 // Delete the version folder if it is less than the new version and not | |
465 // equal to the old version (if we have an old version). | |
466 if (version.get() && | |
467 version->CompareTo(new_version) < 0 && | |
468 (existing_version == NULL || !version->Equals(*existing_version))) { | |
469 // Collect the key files (relative to the version dir) for all products. | |
470 key_files.clear(); | |
471 std::for_each(products_.begin(), products_.end(), | |
472 std::bind2nd(std::mem_fun(&Product::AddKeyFiles), | |
473 &key_files)); | |
474 // Make the key_paths absolute. | |
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 } | |
455 | 480 |
456 // We try to delete all directories whose versions are lower than | 481 VLOG(1) << "Deleting directory: " << next_version.value(); |
robertshield
2011/10/14 21:28:35
"Deleting directory: " -> "Deleting old version di
grt (UTC plus 2)
2011/10/14 22:55:25
Done.
| |
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 | 482 |
481 VLOG(1) << "Deleting directory: " << next_version.value(); | 483 item.reset(WorkItem::CreateDeleteTreeWorkItem(next_version, temp_path, |
482 | 484 key_files)); |
483 scoped_ptr<WorkItem> item( | 485 item->set_ignore_failure(true); |
484 WorkItem::CreateDeleteTreeWorkItem(next_version, temp_path, | 486 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 } | 487 } |
493 | |
494 next_version = version_enum.Next(); | |
495 } | 488 } |
496 } | 489 } |
497 | 490 |
498 void InstallerState::AddComDllList(std::vector<FilePath>* com_dll_list) const { | 491 void InstallerState::AddComDllList(std::vector<FilePath>* com_dll_list) const { |
499 std::for_each(products_.begin(), products_.end(), | 492 std::for_each(products_.begin(), products_.end(), |
500 std::bind2nd(std::mem_fun(&Product::AddComDllList), | 493 std::bind2nd(std::mem_fun(&Product::AddComDllList), |
501 com_dll_list)); | 494 com_dll_list)); |
502 } | 495 } |
503 | 496 |
504 bool InstallerState::SetChannelFlags(bool set, | 497 bool InstallerState::SetChannelFlags(bool set, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 if (is_multi_install()) { | 599 if (is_multi_install()) { |
607 InstallUtil::AddInstallerResultItems( | 600 InstallUtil::AddInstallerResultItems( |
608 system_install, multi_package_binaries_distribution()->GetStateKey(), | 601 system_install, multi_package_binaries_distribution()->GetStateKey(), |
609 status, string_resource_id, launch_cmd, install_list.get()); | 602 status, string_resource_id, launch_cmd, install_list.get()); |
610 } | 603 } |
611 if (!install_list->Do()) | 604 if (!install_list->Do()) |
612 LOG(ERROR) << "Failed to record installer error information in registry."; | 605 LOG(ERROR) << "Failed to record installer error information in registry."; |
613 } | 606 } |
614 | 607 |
615 } // namespace installer | 608 } // namespace installer |
OLD | NEW |