diff options
| author | Alexander Kaspar <alexander.kaspar@gmail.com> | 2016-12-02 16:15:33 +0100 |
|---|---|---|
| committer | Alexander Kaspar <alexander.kaspar@gmail.com> | 2016-12-02 16:15:33 +0100 |
| commit | 813e4214907ae3de4c25834747b7dfb9ec1e2360 (patch) | |
| tree | 00dd4fb47bdd1da71ccd34e5c79e0d49ec90e202 /toolsrc/src/vcpkg.cpp | |
| parent | 62673ac3284a5dbca6e735d6d44ed37fbbbfd714 (diff) | |
| parent | 25b6ef7a9d4ad73ae6123be715a7904c101f31fc (diff) | |
| download | vcpkg-813e4214907ae3de4c25834747b7dfb9ec1e2360.tar.gz vcpkg-813e4214907ae3de4c25834747b7dfb9ec1e2360.zip | |
Merge branch 'master' of https://github.com/Microsoft/vcpkg into qca
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 6c5224f56..88b05b0a9 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -109,6 +109,65 @@ void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) fs::rename(tmp_update_filename, update_filename); } +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; + + for (const std::unique_ptr<StatusParagraph>& pgh : status_db) + { + if (pgh->state != install_state_t::installed) + { + continue; + } + + std::fstream listfile(paths.listfile_path(pgh->package)); + + std::vector<std::string> installed_files_of_current_pgh; + while (std::getline(listfile, line)) + { + if (line.empty()) + { + continue; + } + + 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); + } + + return installed_files; +} + expected<SourceParagraph> vcpkg::try_load_port(const fs::path& path) { try |
