From 56d322dcb12dfaf95cd3cb9976110aa7d0cc9a15 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 28 Feb 2017 18:23:48 -0800 Subject: [PATCH] Improve implementation of `vcpkg integrate remove` --- toolsrc/src/commands_integrate.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index 595cf3914de..3d5a9daeb1a 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -228,20 +228,25 @@ namespace vcpkg::Commands::Integrate static void integrate_remove() { const fs::path path = get_appdata_targets_path(); - if (!fs::exists(path)) + + std::error_code ec; + bool was_deleted = fs::remove(path, ec); + + if (ec) { - System::println(System::color::success, "User-wide integration is not installed"); - exit(EXIT_SUCCESS); + System::println(System::color::error, "Error: Unable to remove user-wide integration: %d", ec.message()); + exit(EXIT_FAILURE); } - const std::wstring cmd_line = Strings::wformat(LR"(DEL "%s")", path.native()); - const int exit_code = System::cmd_execute(cmd_line); - if (exit_code) + if (was_deleted) { - System::println(System::color::error, "Error: Unable to remove user-wide integration: %d", exit_code); - exit(exit_code); + System::println(System::color::success, "User-wide integration was removed"); } - System::println(System::color::success, "User-wide integration was removed"); + else + { + System::println(System::color::success, "User-wide integration is not installed"); + } + exit(EXIT_SUCCESS); }