util: prompt before nuking out directory

This commit is contained in:
Vaxry 2024-03-09 21:44:47 +00:00
parent a5cfddb46f
commit 2e42262ac5

View file

@ -38,6 +38,22 @@ static std::string removeBeginEndSpacesTabs(std::string str) {
return str; return str;
} }
static bool promptForDeletion(const std::string& path) {
std::cout << "About to delete (recursively) " << path << ", are you sure? [Y/n]\n";
std::string result;
std::cin >> result;
if (result != "Y" && result != "Y\n" && result != "y\n" && result != "y") {
std::cout << "Abort.\n";
exit(1);
return false;
}
std::filesystem::remove_all(path);
return true;
}
std::unique_ptr<SCursorTheme> currentTheme; std::unique_ptr<SCursorTheme> currentTheme;
static Hyprlang::CParseResult parseDefineSize(const char* C, const char* V) { static Hyprlang::CParseResult parseDefineSize(const char* C, const char* V) {
@ -181,7 +197,7 @@ static std::optional<std::string> createCursorThemeFromPath(const std::string& p
std::filesystem::create_directory(out); std::filesystem::create_directory(out);
else { else {
// clear the entire thing, avoid melting themes together // clear the entire thing, avoid melting themes together
std::filesystem::remove_all(out); promptForDeletion(out);
std::filesystem::create_directory(out); std::filesystem::create_directory(out);
} }
@ -265,7 +281,7 @@ static std::optional<std::string> extractXTheme(const std::string& xpath, const
std::filesystem::create_directory(out); std::filesystem::create_directory(out);
else { else {
// clear the entire thing, avoid melting themes together // clear the entire thing, avoid melting themes together
std::filesystem::remove_all(out); promptForDeletion(out);
std::filesystem::create_directory(out); std::filesystem::create_directory(out);
} }