util: refuse deleting directories that do not look like themes

This commit is contained in:
Vaxry 2024-03-09 23:03:28 +00:00
parent c96c8e550c
commit 31aff6642a
1 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include <filesystem>
#include <array>
#include <format>
#include <algorithm>
#include <hyprlang.hpp>
#include "internalSharedTypes.hpp"
@ -39,6 +40,20 @@ static std::string removeBeginEndSpacesTabs(std::string str) {
}
static bool promptForDeletion(const std::string& path) {
bool emptyDirectory = !std::filesystem::exists(path);
if (!emptyDirectory) {
const auto IT = std::filesystem::directory_iterator(path);
emptyDirectory = !std::count_if(std::filesystem::begin(IT), std::filesystem::end(IT), [](auto& e) { return e.is_regular_file(); });
}
if (!std::filesystem::exists(path + "/manifest.hl") && std::filesystem::exists(path) && !emptyDirectory) {
std::cout << "Refusing to remove " << path << " because it doesn't look like a hyprcursor theme.\n"
<< "Please set a valid, empty, nonexistent, or a theme directory as an output path\n";
exit(1);
}
std::cout << "About to delete (recursively) " << path << ", are you sure? [Y/n]\n";
std::string result;
std::cin >> result;