From ccca198c1b1730b0241911cb56dc8e3504958b2a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sun, 18 Sep 2016 20:50:08 -0700 Subject: Initial commit --- toolsrc/src/commands_remove.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 toolsrc/src/commands_remove.cpp (limited to 'toolsrc/src/commands_remove.cpp') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp new file mode 100644 index 000000000..f5315ccb1 --- /dev/null +++ b/toolsrc/src/commands_remove.cpp @@ -0,0 +1,43 @@ +#include "vcpkg_Commands.h" +#include "vcpkg.h" +#include "vcpkg_System.h" + +namespace vcpkg +{ + static const std::string OPTION_PURGE = "--purge"; + + static void delete_directory(const fs::path& directory) + { + std::error_code ec; + fs::remove_all(directory, ec); + if (!ec) + { + System::println(System::color::success, "Cleaned up %s", directory.string()); + } + if (fs::exists(directory)) + { + System::println(System::color::warning, "Some files in %s were unable to be removed. Close any editors operating in this directory and retry.", directory.string()); + } + } + + void remove_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) + { + const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); + auto status_db = database_load_check(paths); + + std::vector specs = args.parse_all_arguments_as_package_specs(default_target_triplet); + bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); + + for (const package_spec& spec : specs) + { + deinstall_package(paths, spec, status_db); + + if (alsoRemoveFolderFromPackages) + { + const fs::path spec_package_dir = paths.packages / spec.dir(); + delete_directory(spec_package_dir); + } + } + exit(EXIT_SUCCESS); + } +} -- cgit v1.2.3