-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmd_uninstall.cpp
69 lines (57 loc) · 1.85 KB
/
cmd_uninstall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "cmd_uninstall.hpp"
#include "build_info.hpp"
#include <fmt/core.h>
#include <spdlog/spdlog.h>
#include <unistd.h>
#include <filesystem>
#include <string>
using namespace rocvad;
CmdUninstall::CmdUninstall(CLI::App& parent)
{
register_command(
parent.add_subcommand("uninstall", "Uninstall driver and tool from system"));
}
bool CmdUninstall::execute(const Environment& env)
{
if (geteuid() != 0) {
spdlog::error("should be run with root privileges\ntry \"sudo {} uninstall\"",
BuildInfo::tool_name);
return false;
}
int n_ok = 0, n_warn = 0, n_err = 0;
for (const std::string path : {BuildInfo::driver_bundle_path, BuildInfo::tool_path}) {
if (path == BuildInfo::tool_path && n_err != 0) {
spdlog::warn(
"can't remove \"{}\": Skipping because of previous errors", path);
n_warn++;
continue;
}
std::error_code err;
const auto n_removed = std::filesystem::remove_all(path, err);
if (n_removed != 0 && !err) {
fmt::println("removed {}", path);
n_ok++;
} else if (n_removed == 0 && !err) {
spdlog::warn("can't remove \"{}\": Not found", path);
n_warn++;
} else if (err) {
spdlog::error("can't remove \"{}\": {}", path, err.message());
n_err++;
}
}
if (n_ok == 0) {
fmt::println("nothing removed");
} else if (n_err == 0) {
fmt::println("everything removed");
} else {
fmt::println("completed with errors");
}
return (n_err == 0);
}