InstallationDirs struct now checks/create the needed dirs
MODIFY
include/vcpkg_Commands.h
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);

MODIFY
src/commands_install.cpp
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);

InstallationDirs struct now checks/create the needed dirs