diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-17 18:18:47 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-17 19:04:17 -0700 |
| commit | 4da39c6ca6e70734abe7b3d880e6987b7783fe36 (patch) | |
| tree | 83152d912ac6c1fcc047b793b71e1b64e8498b5d | |
| parent | c8ff4e39ba313b7ad6d3daa0d604e5f648a04d71 (diff) | |
| download | vcpkg-4da39c6ca6e70734abe7b3d880e6987b7783fe36.tar.gz vcpkg-4da39c6ca6e70734abe7b3d880e6987b7783fe36.zip | |
InstallationDirs struct now checks/create the needed dirs
| -rw-r--r-- | toolsrc/include/vcpkg_Commands.h | 13 | ||||
| -rw-r--r-- | toolsrc/src/commands_install.cpp | 33 |
2 files changed, 42 insertions, 4 deletions
diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h index 21c82cea2..8535e27c4 100644 --- a/toolsrc/include/vcpkg_Commands.h +++ b/toolsrc/include/vcpkg_Commands.h @@ -45,10 +45,19 @@ namespace vcpkg::Commands { struct InstallationDirs { + static InstallationDirs initiliaze_dirs(Files::Filesystem& fs, + const fs::path& source_dir, + const fs::path& destination_root, + const std::string& destination_subdirectory, + const fs::path& listfile); + + fs::path source_dir; // "source" from source-destination, not source code. fs::path destination_root; std::string destination_subdirectory; fs::path listfile; + + fs::path destination() const; }; void install_files_and_write_listfile(Files::Filesystem& fs, const InstallationDirs& dirs); @@ -167,7 +176,7 @@ namespace vcpkg::Commands void perform_and_exit(const VcpkgCmdArguments& args); } - template <class T> + template<class T> struct PackageNameAndFunction { std::string name; @@ -178,7 +187,7 @@ namespace vcpkg::Commands const std::vector<PackageNameAndFunction<CommandTypeB>>& get_available_commands_type_b(); const std::vector<PackageNameAndFunction<CommandTypeC>>& get_available_commands_type_c(); - template <typename T> + template<typename T> T find(const std::string& command_name, const std::vector<PackageNameAndFunction<T>> available_commands) { for (const PackageNameAndFunction<T>& cmd : available_commands) diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index 05d1e32eb..8c7ffba7e 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -15,15 +15,44 @@ namespace vcpkg::Commands::Install using Dependencies::RequestType; using Dependencies::InstallPlanType; + InstallationDirs InstallationDirs::initiliaze_dirs(Files::Filesystem& fs, + const fs::path& source_dir, + const fs::path& destination_root, + const std::string& destination_subdirectory, + const fs::path& listfile) + { + std::error_code ec; + InstallationDirs dirs; + dirs.source_dir = source_dir; + Checks::check_exit(VCPKG_LINE_INFO, fs.exists(dirs.source_dir), "Source directory %s does not exist", dirs.source_dir.generic_string()); + + dirs.destination_root = destination_root; + dirs.destination_subdirectory = destination_subdirectory; + const fs::path destination = dirs.destination_root / dirs.destination_subdirectory; + fs.create_directories(destination, ec); + Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.generic_string()); + + dirs.listfile = listfile; + const fs::path listfile_parent = listfile.parent_path(); + fs.create_directories(listfile_parent, ec); + Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", dirs.listfile.generic_string()); + + return dirs; + } + + fs::path InstallationDirs::destination() const + { + return this->destination_root / this->destination_subdirectory; + } + void install_files_and_write_listfile(Files::Filesystem& fs, const InstallationDirs& dirs) { std::vector<std::string> output; const size_t prefix_length = dirs.source_dir.native().size(); - const fs::path destination = dirs.destination_root / dirs.destination_subdirectory; + const fs::path destination = dirs.destination(); std::error_code ec; - fs.create_directory(destination, ec); output.push_back(Strings::format(R"(%s/)", dirs.destination_subdirectory)); auto files = fs.get_files_recursive(dirs.source_dir); |
