aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorAlexander Kaspar <alexander.kaspar@gmail.com>2016-12-02 16:15:33 +0100
committerAlexander Kaspar <alexander.kaspar@gmail.com>2016-12-02 16:15:33 +0100
commit813e4214907ae3de4c25834747b7dfb9ec1e2360 (patch)
tree00dd4fb47bdd1da71ccd34e5c79e0d49ec90e202 /toolsrc/src
parent62673ac3284a5dbca6e735d6d44ed37fbbbfd714 (diff)
parent25b6ef7a9d4ad73ae6123be715a7904c101f31fc (diff)
downloadvcpkg-813e4214907ae3de4c25834747b7dfb9ec1e2360.tar.gz
vcpkg-813e4214907ae3de4c25834747b7dfb9ec1e2360.zip
Merge branch 'master' of https://github.com/Microsoft/vcpkg into qca
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/commands_installation.cpp74
-rw-r--r--toolsrc/src/commands_owns.cpp21
-rw-r--r--toolsrc/src/vcpkg.cpp59
3 files changed, 109 insertions, 45 deletions
diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp
index 23342070d..1abd16796 100644
--- a/toolsrc/src/commands_installation.cpp
+++ b/toolsrc/src/commands_installation.cpp
@@ -128,53 +128,67 @@ namespace vcpkg
listfile.close();
}
- static std::map<std::string, fs::path> remove_first_n_chars_and_map(const std::vector<fs::path> absolute_paths, const size_t n)
+ static void remove_first_n_chars(std::vector<std::string>* strings, const size_t n)
{
- std::map<std::string, fs::path> output;
-
- for (const fs::path& absolute_path : absolute_paths)
+ for (std::string& s : *strings)
{
- std::string suffix = absolute_path.generic_string();
- suffix.erase(0, n);
- output.emplace(suffix, absolute_path);
+ s.erase(0, n);
}
+ };
- return output;
- }
-
- static void print_map_values(const std::vector<std::string> keys, const std::map<std::string, fs::path>& map)
+ static std::vector<std::string> extract_files_in_triplet(const std::vector<StatusParagraph_and_associated_files>& pgh_and_files, const triplet& triplet)
{
- System::println("");
- for (const std::string& key : keys)
+ std::vector<std::string> output;
+ for (const StatusParagraph_and_associated_files& t : pgh_and_files)
{
- System::println(" %s", map.at(key).generic_string());
+ if (t.pgh.package.spec.target_triplet() != triplet)
+ {
+ continue;
+ }
+
+ output.insert(output.end(), t.files.cbegin(), t.files.cend());
}
- System::println("");
+
+ std::sort(output.begin(), output.end());
+ return output;
}
- static void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db)
+ void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db)
{
const fs::path package_dir = paths.package_dir(binary_paragraph.spec);
- const std::vector<fs::path> package_files = Files::recursive_find_all_files_in_dir(package_dir);
-
- const fs::path installed_dir = paths.installed / binary_paragraph.spec.target_triplet().canonical_name();
- const std::vector<fs::path> installed_files = Files::recursive_find_all_files_in_dir(installed_dir);
-
- const std::map<std::string, fs::path> package_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(package_files, package_dir.generic_string().size() + 1);
- const std::map<std::string, fs::path> installed_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(installed_files, installed_dir.generic_string().size() + 1);
-
- const std::vector<std::string> package_files_set = Maps::extract_keys(package_files_relative_paths_to_absolute_paths);
- const std::vector<std::string> installed_files_set = Maps::extract_keys(installed_files_relative_paths_to_absolute_paths);
+ const std::vector<fs::path> package_file_paths = Files::recursive_find_all_files_in_dir(package_dir);
+ std::vector<std::string> package_files;
+ const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash
+ std::transform(package_file_paths.cbegin(), package_file_paths.cend(), std::back_inserter(package_files), [package_remove_char_count](const fs::path& path)
+ {
+ return path.generic_string().erase(0, package_remove_char_count);
+ });
+ std::sort(package_files.begin(), package_files.end());
+
+ const std::vector<StatusParagraph_and_associated_files>& pgh_and_files = get_installed_files(paths, status_db);
+ const triplet& triplet = binary_paragraph.spec.target_triplet();
+ 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()); // Should already be sorted
std::vector<std::string> intersection;
- std::set_intersection(package_files_set.cbegin(), package_files_set.cend(),
- installed_files_set.cbegin(), installed_files_set.cend(),
+ std::set_intersection(package_files.cbegin(), package_files.cend(),
+ installed_files.cbegin(), installed_files.cend(),
std::back_inserter(intersection));
if (!intersection.empty())
{
- System::println(System::color::error, "The following files are already installed and are in conflict with %s:", binary_paragraph.spec);
- print_map_values(intersection, installed_files_relative_paths_to_absolute_paths);
+ const fs::path triplet_install_path = paths.installed / triplet.canonical_name();
+ System::println(System::color::error, "The following files are already installed in %s and are in conflict with %s",
+ triplet_install_path.generic_string(),
+ binary_paragraph.spec);
+ System::println("");
+ for (const std::string& s : intersection)
+ {
+ System::println(" %s", s);
+ }
+ System::println("");
exit(EXIT_FAILURE);
}
diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp
index e5599ce01..45f073304 100644
--- a/toolsrc/src/commands_owns.cpp
+++ b/toolsrc/src/commands_owns.cpp
@@ -1,30 +1,21 @@
#include "vcpkg_Commands.h"
#include "vcpkg_System.h"
#include "vcpkg.h"
-#include <fstream>
namespace vcpkg
{
static void search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db)
{
- std::string line;
-
- for (auto&& pgh : status_db)
+ const std::vector<StatusParagraph_and_associated_files> installed_files = get_installed_files(paths, status_db);
+ for (const StatusParagraph_and_associated_files& pgh_and_file : installed_files)
{
- if (pgh->state != install_state_t::installed)
- continue;
+ const StatusParagraph& pgh = pgh_and_file.pgh;
- std::fstream listfile(paths.listfile_path(pgh->package));
- while (std::getline(listfile, line))
+ for (const std::string& file : pgh_and_file.files)
{
- if (line.empty())
- {
- continue;
- }
-
- if (line.find(file_substr) != std::string::npos)
+ if (file.find(file_substr) != std::string::npos)
{
- System::println("%s: %s", pgh->package.displayname(), line);
+ System::println("%s: %s", pgh.package.displayname(), file);
}
}
}
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