diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-29 16:00:41 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-31 16:15:05 -0700 |
| commit | f1d4a4457ece7067bff16479b6e86d06770d3095 (patch) | |
| tree | e8d10403053b5aed8a34d80867c37d06207a4a44 /toolsrc | |
| parent | b3773070fee854ad7a9ea93b8f65b09239947f36 (diff) | |
| download | vcpkg-f1d4a4457ece7067bff16479b6e86d06770d3095.tar.gz vcpkg-f1d4a4457ece7067bff16479b6e86d06770d3095.zip | |
Introduce get_installed_ports()
Diffstat (limited to 'toolsrc')
| -rw-r--r-- | toolsrc/include/vcpkglib.h | 1 | ||||
| -rw-r--r-- | toolsrc/src/commands_list.cpp | 22 | ||||
| -rw-r--r-- | toolsrc/src/commands_update.cpp | 7 | ||||
| -rw-r--r-- | toolsrc/src/vcpkglib.cpp | 13 |
4 files changed, 24 insertions, 19 deletions
diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h index 710b21cd5..864c7de79 100644 --- a/toolsrc/include/vcpkglib.h +++ b/toolsrc/include/vcpkglib.h @@ -18,6 +18,7 @@ namespace vcpkg ImmutableSortedVector<std::string> files; }; + std::vector<StatusParagraph*> get_installed_ports(const StatusParagraphs& status_db); std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db); diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index cee95767b..f7b6bd778 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -22,13 +22,7 @@ namespace vcpkg::Commands::List args.check_and_get_optional_command_arguments({}); const StatusParagraphs status_paragraphs = database_load_check(paths); - std::vector<StatusParagraph> installed_packages; - for (auto&& pgh : status_paragraphs) - { - if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) - continue; - installed_packages.push_back(*pgh); - } + std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_paragraphs); if (installed_packages.empty()) { @@ -37,30 +31,30 @@ namespace vcpkg::Commands::List } std::sort(installed_packages.begin(), installed_packages.end(), - [ ]( const StatusParagraph& lhs, const StatusParagraph& rhs ) -> bool + [ ]( const StatusParagraph* lhs, const StatusParagraph* rhs ) -> bool { - return lhs.package.displayname() < rhs.package.displayname(); + return lhs->package.displayname() < rhs->package.displayname(); }); if (args.command_arguments.size() == 0) { - for (const StatusParagraph& status_paragraph : installed_packages) + for (const StatusParagraph* status_paragraph : installed_packages) { - do_print(status_paragraph); + do_print(*status_paragraph); } } else { // At this point there is 1 argument - for (const StatusParagraph& status_paragraph : installed_packages) + for (const StatusParagraph* status_paragraph : installed_packages) { - const std::string displayname = status_paragraph.package.displayname(); + const std::string displayname = status_paragraph->package.displayname(); if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end()) { continue; } - do_print(status_paragraph); + do_print(*status_paragraph); } } diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 4dbedff05..34b49e321 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -18,13 +18,11 @@ namespace vcpkg::Commands::Update const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports); const std::map<std::string, std::string> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs); - std::string packages_list; + std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db); std::vector<std::string> packages_output; - for (auto&& pgh : status_db) + for (const StatusParagraph* pgh : installed_packages) { - if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) - continue; auto it = src_names_to_versions.find(pgh->package.spec.name()); if (it == src_names_to_versions.end()) { @@ -37,7 +35,6 @@ namespace vcpkg::Commands::Update pgh->package.displayname(), pgh->package.version, it->second)); - packages_list.append(" " + pgh->package.displayname()); } } std::sort(packages_output.begin(), packages_output.end()); diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp index cfdb17002..e96f1c33f 100644 --- a/toolsrc/src/vcpkglib.cpp +++ b/toolsrc/src/vcpkglib.cpp @@ -171,6 +171,19 @@ namespace vcpkg fs::rename(updated_listfile_path, listfile_path); } + std::vector<StatusParagraph*> get_installed_ports(const StatusParagraphs& status_db) + { + std::vector<StatusParagraph*> installed_packages; + for (auto&& pgh : status_db) + { + if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) + continue; + installed_packages.push_back(pgh.get()); + } + + return installed_packages; + } + std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) { std::vector<StatusParagraph_and_associated_files> installed_files; |
