From 4da39c6ca6e70734abe7b3d880e6987b7783fe36 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 17 Apr 2017 18:18:47 -0700 Subject: InstallationDirs struct now checks/create the needed dirs --- toolsrc/src/commands_install.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') 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 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); -- cgit v1.2.3