diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-09-18 20:50:08 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2016-09-18 20:54:03 -0700 |
| commit | ccca198c1b1730b0241911cb56dc8e3504958b2a (patch) | |
| tree | a2dd9b8b087a09afdcecc5cbb3377bed15127eb2 /toolsrc/src/commands_remove.cpp | |
| download | vcpkg-ccca198c1b1730b0241911cb56dc8e3504958b2a.tar.gz vcpkg-ccca198c1b1730b0241911cb56dc8e3504958b2a.zip | |
Initial commit
Diffstat (limited to 'toolsrc/src/commands_remove.cpp')
| -rw-r--r-- | toolsrc/src/commands_remove.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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<std::string> options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); + auto status_db = database_load_check(paths); + + std::vector<package_spec> 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); + } +} |
