lib: improve access checks on themes

This commit is contained in:
Vaxry 2024-03-26 15:26:26 +00:00
parent 1a1fcfb58d
commit d3876f3477

View file

@ -49,14 +49,21 @@ static std::string getFirstTheme(PHYPRCURSORLOGFUNC logfn) {
for (auto& dir : userThemeDirs) { for (auto& dir : userThemeDirs) {
const auto FULLPATH = HOME + dir; const auto FULLPATH = HOME + dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
if (std::filesystem::exists(MANIFESTPATH)) { if (std::filesystem::exists(MANIFESTPATH)) {
@ -68,17 +75,24 @@ static std::string getFirstTheme(PHYPRCURSORLOGFUNC logfn) {
for (auto& dir : systemThemeDirs) { for (auto& dir : systemThemeDirs) {
const auto FULLPATH = dir; const auto FULLPATH = dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
if (std::filesystem::exists(MANIFESTPATH)) { if (!std::filesystem::exists(MANIFESTPATH)) {
Debug::log(HC_LOG_INFO, logfn, "getFirstTheme: found {}", themeDir.path().string()); Debug::log(HC_LOG_INFO, logfn, "getFirstTheme: found {}", themeDir.path().string());
return themeDir.path().stem().string(); return themeDir.path().stem().string();
} }
@ -97,14 +111,21 @@ static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORL
for (auto& dir : userThemeDirs) { for (auto& dir : userThemeDirs) {
const auto FULLPATH = HOME + dir; const auto FULLPATH = HOME + dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
if (name.empty()) { if (name.empty()) {
@ -138,16 +159,20 @@ static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORL
for (auto& dir : systemThemeDirs) { for (auto& dir : systemThemeDirs) {
const auto FULLPATH = dir; const auto FULLPATH = dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue; continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";