Manager+Test: Move exclude paths and system directories to config
This commit is contained in:
@@ -37,6 +37,8 @@ public:
|
||||
Config(s);
|
||||
virtual ~Config();
|
||||
|
||||
void setSystemDirectories(const std::vector<std::filesystem::path>& systemDirectories) { m_settings.systemDirectories = systemDirectories; }
|
||||
void setExcludePaths(const std::map<std::string, std::string>& excludePaths) { m_settings.excludePaths = excludePaths; }
|
||||
void setVerbose(bool verbose) { m_verbose = verbose; }
|
||||
|
||||
const std::map<std::string, std::string>& excludePaths() const { return m_settings.excludePaths; }
|
||||
|
||||
+8
-8
@@ -353,19 +353,19 @@ void Dotfile::forEachDotfile(const std::vector<std::string>& targets, const std:
|
||||
|
||||
bool Dotfile::filter(const std::filesystem::path& path)
|
||||
{
|
||||
for (auto& excludePath : m_excludePaths) {
|
||||
if (excludePath.type == ExcludeType::File) {
|
||||
if (path.string() == Config::the().workingDirectory() / excludePath.path) {
|
||||
for (auto& excludePath : Config::the().excludePaths()) {
|
||||
if (excludePath.second == "file") {
|
||||
if (path.string() == Config::the().workingDirectory() / excludePath.first) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (excludePath.type == ExcludeType::Directory) {
|
||||
if (path.string().find(Config::the().workingDirectory() / excludePath.path) == 0) {
|
||||
else if (excludePath.second == "directory") {
|
||||
if (path.string().find(Config::the().workingDirectory() / excludePath.first) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (excludePath.type == ExcludeType::EndsWith) {
|
||||
if (path.string().find(excludePath.path) == path.string().size() - excludePath.path.size()) {
|
||||
else if (excludePath.second == "endsWith") {
|
||||
if (path.string().find(excludePath.first) == path.string().size() - excludePath.first.size()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -387,7 +387,7 @@ bool Dotfile::include(const std::filesystem::path& path, const std::vector<std::
|
||||
|
||||
bool Dotfile::isSystemTarget(const std::string& target)
|
||||
{
|
||||
for (const auto& systemDirectory : m_systemDirectories) {
|
||||
for (const auto& systemDirectory : Config::the().systemDirectories()) {
|
||||
|
||||
if (target.find(systemDirectory) == 0) {
|
||||
return true;
|
||||
|
||||
@@ -25,25 +25,11 @@ public:
|
||||
Push,
|
||||
};
|
||||
|
||||
enum class ExcludeType {
|
||||
File,
|
||||
Directory,
|
||||
EndsWith,
|
||||
};
|
||||
|
||||
struct ExcludePath {
|
||||
ExcludeType type;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
void add(const std::vector<std::string>& targets = {});
|
||||
void list(const std::vector<std::string>& targets = {});
|
||||
void pull(const std::vector<std::string>& targets = {});
|
||||
void push(const std::vector<std::string>& targets = {});
|
||||
|
||||
void setSystemDirectories(const std::vector<std::filesystem::path>& systemDirectories) { m_systemDirectories = systemDirectories; }
|
||||
void setExcludePaths(const std::vector<ExcludePath>& excludePaths) { m_excludePaths = excludePaths; }
|
||||
|
||||
private:
|
||||
void pullOrPush(SyncType type, const std::vector<std::string>& targets = {});
|
||||
void sync(SyncType type,
|
||||
@@ -56,9 +42,6 @@ private:
|
||||
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);
|
||||
|
||||
std::vector<ExcludePath> m_excludePaths;
|
||||
std::vector<std::filesystem::path> m_systemDirectories;
|
||||
};
|
||||
|
||||
#endif // DOTFILE_H
|
||||
|
||||
@@ -54,21 +54,6 @@ int main(int argc, const char* argv[])
|
||||
Config::the().setVerbose(verbose);
|
||||
|
||||
if (fileOperation) {
|
||||
Dotfile::the().setExcludePaths({
|
||||
{ Dotfile::ExcludeType::File, "dotfiles.sh" },
|
||||
{ Dotfile::ExcludeType::File, "packages" },
|
||||
{ Dotfile::ExcludeType::EndsWith, ".md" },
|
||||
{ Dotfile::ExcludeType::EndsWith, "README.org" },
|
||||
{ Dotfile::ExcludeType::Directory, ".git" },
|
||||
{ Dotfile::ExcludeType::File, "screenshot.png" },
|
||||
|
||||
{ Dotfile::ExcludeType::Directory, ".cache" },
|
||||
{ Dotfile::ExcludeType::Directory, "CMakeFiles" },
|
||||
{ Dotfile::ExcludeType::Directory, "cppcheck-cppcheck-build-dir" },
|
||||
});
|
||||
|
||||
Dotfile::the().setSystemDirectories({ "/boot", "/etc", "/usr/share" });
|
||||
|
||||
if (addOrAur) {
|
||||
Dotfile::the().add(targets);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user