Manager: Add function to check if file is system type

This commit is contained in:
Riyyi
2021-09-23 17:24:17 +02:00
parent e7d1515fca
commit 58bf5b98ee
2 changed files with 13 additions and 9 deletions
+12 -9
View File
@@ -45,7 +45,6 @@ void Dotfile::add(const std::vector<std::string>& targets)
std::vector<size_t> systemTargets;
// Separate home and system targets
bool isSystem = false;
for (size_t i = 0; i < targets.size(); ++i) {
if (!std::filesystem::is_regular_file(targets.at(i))
&& !std::filesystem::is_directory(targets.at(i))
@@ -54,14 +53,7 @@ void Dotfile::add(const std::vector<std::string>& targets)
continue;
}
isSystem = false;
for (const auto& systemDirectory : s_systemDirectories) {
if (targets.at(i).find(systemDirectory) == 0) {
isSystem = true;
}
}
if (isSystem) {
if (isSystemTarget(targets.at(i))) {
systemTargets.push_back(i);
}
else {
@@ -218,4 +210,15 @@ bool Dotfile::include(const std::filesystem::path& path, const std::vector<std::
return false;
}
bool Dotfile::isSystemTarget(const std::string& target)
{
for (const auto& systemDirectory : s_systemDirectories) {
if (target.find(systemDirectory) == 0) {
return true;
}
}
return false;
}
} // namespace Util
+1
View File
@@ -42,6 +42,7 @@ private:
void forEachDotfile(const std::vector<std::string>& targets, const std::function<void(std::filesystem::directory_entry, size_t, size_t)>& callback);
bool filter(const std::filesystem::path& path);
bool include(const std::filesystem::path& path, const std::vector<std::string>& targets);
bool isSystemTarget(const std::string& target);
static std::vector<ExcludePath> s_excludePaths;
static std::vector<std::filesystem::path> s_systemDirectories;