Manager: Add new pattern logic to system config files

This commit is contained in:
Riyyi
2022-03-08 00:06:01 +01:00
parent 3b4ea3f42d
commit db22cc9f06
7 changed files with 27 additions and 43 deletions
+3 -19
View File
@@ -51,7 +51,8 @@ void Dotfile::add(const std::vector<std::string>& targets)
continue;
}
if (isSystemTarget(targets.at(i))) {
if (match(std::filesystem::directory_entry { targets.at(i) },
Config::the().systemPatterns())) {
systemIndices.push_back(i);
}
else {
@@ -243,7 +244,7 @@ void Dotfile::pullOrPush(SyncType type, const std::vector<std::string>& targets)
// Separate home and system targets
forEachDotfile(targets, [&](const std::filesystem::directory_entry& path, size_t index) {
dotfiles.push_back(path.path().string());
if (isSystemTarget(path.path().string())) {
if (match(path, Config::the().systemPatterns())) {
systemIndices.push_back(index);
}
else {
@@ -500,20 +501,3 @@ void Dotfile::forEachDotfile(const std::vector<std::string>& targets, const std:
callback(path, index++);
}
}
bool Dotfile::isSystemTarget(const std::string& target)
{
for (const auto& systemDirectory : Config::the().systemDirectories()) {
if (target.find(systemDirectory) == 0) {
return true;
}
// FIXME: The second filesystem::path cant have a "/" as the first character,
// as it will think the path is at the root.
if (target.find(Config::the().workingDirectory().string() + systemDirectory.string()) == 0) {
return true;
}
}
return false;
}