diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-01 20:39:28 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-01 20:39:28 -0800 |
| commit | a195dedf52e67b1aaac62f041cc767e0d12592b3 (patch) | |
| tree | 8bccd8ee88bd28f8f3377c63b96d2180f09ceaf6 /toolsrc/src | |
| parent | a8c189c3f29dcb081ffe7c1bda53bdc82ac6dc92 (diff) | |
| download | vcpkg-a195dedf52e67b1aaac62f041cc767e0d12592b3.tar.gz vcpkg-a195dedf52e67b1aaac62f041cc767e0d12592b3.zip | |
get_installed_files() now filters out the directories
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/commands_installation.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 8bae0a182..1abd16796 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -170,7 +170,7 @@ namespace vcpkg std::vector<std::string> installed_files = extract_files_in_triplet(pgh_and_files, triplet); const size_t installed_remove_char_count = triplet.canonical_name().size() + 1; // +1 for the slash remove_first_n_chars(&installed_files, installed_remove_char_count); - std::sort(installed_files.begin(), installed_files.end()); + std::sort(installed_files.begin(), installed_files.end()); // Should already be sorted std::vector<std::string> intersection; std::set_intersection(package_files.cbegin(), package_files.cend(), diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 57b2e7adb..88b05b0a9 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -111,6 +111,8 @@ void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) std::vector<StatusParagraph_and_associated_files> vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) { + static const std::string MARK_FOR_REMOVAL = ""; + std::vector<StatusParagraph_and_associated_files> installed_files; std::string line; @@ -135,6 +137,30 @@ std::vector<StatusParagraph_and_associated_files> vcpkg::get_installed_files(con installed_files_of_current_pgh.push_back(line); } + // Should already be sorted + std::sort(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end()); + + // Since the files are sorted, we can detect the entries that represent directories + // by comparing every element with the next one and checking if the next has a slash immediately after the current one's length + for (int i = 1; i < installed_files_of_current_pgh.size(); i++) + { + std::string& current_string = installed_files_of_current_pgh.at(i - 1); + const std::string& next_string = installed_files_of_current_pgh.at(i); + + const size_t potential_slash_char_index = current_string.length(); + // Make sure the index exists first + if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/') + { + current_string = MARK_FOR_REMOVAL; + } + } + + installed_files_of_current_pgh.erase(std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) + { + return file == MARK_FOR_REMOVAL; + }), + installed_files_of_current_pgh.end()); + const StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; installed_files.push_back(pgh_and_files); } |
