logic: implemented usage of FilePathFilters for excluded paths
* removed check in settings for existing paths of exclude filters
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
|
||||
FileManager::FileManager()
|
||||
{
|
||||
@@ -15,11 +16,11 @@ FileManager::~FileManager()
|
||||
|
||||
void FileManager::update(
|
||||
const std::vector<FilePath>& sourcePaths,
|
||||
const std::vector<FilePath>& excludePaths,
|
||||
const std::vector<FilePathFilter>& excludeFilters,
|
||||
const std::vector<std::wstring>& sourceExtensions
|
||||
){
|
||||
m_sourcePaths = sourcePaths;
|
||||
m_excludePaths = makeCanonical(excludePaths);
|
||||
m_excludeFilters = excludeFilters;
|
||||
m_sourceExtensions = sourceExtensions;
|
||||
|
||||
m_allSourceFilePaths.clear();
|
||||
@@ -85,9 +86,9 @@ std::vector<FilePath> FileManager::makeCanonical(const std::vector<FilePath>& fi
|
||||
|
||||
bool FileManager::isExcluded(const FilePath& filePath) const
|
||||
{
|
||||
for (const FilePath& path : m_excludePaths)
|
||||
for (const FilePathFilter& filter : m_excludeFilters)
|
||||
{
|
||||
if (path == filePath || path.contains(filePath))
|
||||
if (filter.isMatching(filePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
class FilePath;
|
||||
class FilePathFilter;
|
||||
|
||||
class FileManager
|
||||
{
|
||||
@@ -16,7 +17,7 @@ public:
|
||||
|
||||
void update(
|
||||
const std::vector<FilePath>& sourcePaths,
|
||||
const std::vector<FilePath>& excludePaths,
|
||||
const std::vector<FilePathFilter>& excludeFilters,
|
||||
const std::vector<std::wstring>& sourceExtensions
|
||||
);
|
||||
|
||||
@@ -35,7 +36,7 @@ private:
|
||||
bool isExcluded(const FilePath& filePath) const;
|
||||
|
||||
std::vector<FilePath> m_sourcePaths;
|
||||
std::vector<FilePath> m_excludePaths;
|
||||
std::vector<FilePathFilter> m_excludeFilters;
|
||||
std::vector<std::wstring> m_sourceExtensions;
|
||||
|
||||
std::set<FilePath> m_allSourceFilePaths;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
|
||||
FilePathFilter::FilePathFilter(const std::wstring& filterString)
|
||||
: m_filterString(filterString)
|
||||
, m_filterRegex(convertFilterStringToRegex(filterString))
|
||||
{
|
||||
}
|
||||
|
||||
std::wstring FilePathFilter::wstr() const
|
||||
{
|
||||
return m_filterString;
|
||||
}
|
||||
|
||||
bool FilePathFilter::isMatching(const FilePath& filePath) const
|
||||
{
|
||||
const std::wstring s = filePath.wstr();
|
||||
std::wsmatch match;
|
||||
return std::regex_match(s, match, m_filterRegex);
|
||||
}
|
||||
|
||||
bool FilePathFilter::operator<(const FilePathFilter& other) const
|
||||
{
|
||||
return m_filterString.compare(other.m_filterString) < 0;
|
||||
}
|
||||
|
||||
std::wregex FilePathFilter::convertFilterStringToRegex(const std::wstring& filterString)
|
||||
{
|
||||
std::wstring regexFilterString = filterString;
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\\\/]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\\\/]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"([^\\\\])([^/])([\\]])");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"$1$2[\\]]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"([\\[])([^\\\\])");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\[]$2");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\(]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\(]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\)]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\)]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\{]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\{]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\}]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\}]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\+]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\+]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\-]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\-]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\$]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\$]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\.]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\.]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\^]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\^]");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\*][\\*]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L".{0,}");
|
||||
}
|
||||
|
||||
{
|
||||
std::wregex regex(L"[\\*]");
|
||||
regexFilterString = std::regex_replace(regexFilterString, regex, L"[^\\\\/]*");
|
||||
}
|
||||
|
||||
return std::wregex(regexFilterString);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef FILE_PATH_FILTER_H
|
||||
#define FILE_PATH_FILTER_H
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class FilePathFilter
|
||||
{
|
||||
public:
|
||||
FilePathFilter(const std::wstring& filterString);
|
||||
|
||||
std::wstring wstr() const;
|
||||
|
||||
bool isMatching(const FilePath& filePath) const;
|
||||
|
||||
bool operator<(const FilePathFilter& other) const;
|
||||
|
||||
private:
|
||||
static std::wregex convertFilterStringToRegex(const std::wstring& filterString);
|
||||
|
||||
std::wstring m_filterString;
|
||||
std::wregex m_filterRegex;
|
||||
};
|
||||
|
||||
#endif // FILE_PATH_FILTER_H
|
||||
@@ -1,17 +1,18 @@
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
|
||||
FileRegister::FileRegister(
|
||||
const FileRegisterStateData& stateData,
|
||||
const FilePath& currentPath,
|
||||
const std::set<FilePath>& indexedPaths,
|
||||
const std::set<FilePath>& excludedPaths
|
||||
const std::set<FilePathFilter>& excludeFilters
|
||||
)
|
||||
: m_stateData(stateData)
|
||||
, m_currentPath(currentPath)
|
||||
, m_indexedPaths(indexedPaths)
|
||||
, m_excludedPaths(excludedPaths)
|
||||
, m_excludeFilters(excludeFilters)
|
||||
, m_hasFilePathCache(
|
||||
[&](const std::wstring& f)
|
||||
{
|
||||
@@ -48,23 +49,12 @@ FileRegister::FileRegister(
|
||||
|
||||
if (ret)
|
||||
{
|
||||
for (const FilePath& excluded: m_excludedPaths)
|
||||
for (const FilePathFilter& excludeFilter: m_excludeFilters)
|
||||
{
|
||||
if (excluded.isDirectory())
|
||||
if (excludeFilter.isMatching(filePath))
|
||||
{
|
||||
if (excluded.contains(filePath))
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (excluded == filePath)
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "utility/file/FileRegisterStateData.h"
|
||||
#include "utility/UnorderedCache.h"
|
||||
|
||||
class FilePathFilter;
|
||||
|
||||
class FileRegister
|
||||
{
|
||||
public:
|
||||
@@ -13,7 +15,7 @@ public:
|
||||
const FileRegisterStateData& stateData,
|
||||
const FilePath& currentPath,
|
||||
const std::set<FilePath>& indexedPaths,
|
||||
const std::set<FilePath>& excludedPaths
|
||||
const std::set<FilePathFilter>& excludeFilters
|
||||
);
|
||||
virtual ~FileRegister();
|
||||
|
||||
@@ -28,7 +30,7 @@ private:
|
||||
FileRegisterStateData m_stateData;
|
||||
const FilePath& m_currentPath;
|
||||
const std::set<FilePath> m_indexedPaths;
|
||||
const std::set<FilePath> m_excludedPaths;
|
||||
const std::set<FilePathFilter> m_excludeFilters;
|
||||
mutable UnorderedCache<std::wstring, bool> m_hasFilePathCache;
|
||||
};
|
||||
|
||||
|
||||
@@ -132,10 +132,14 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
return files;
|
||||
}
|
||||
|
||||
std::set<FilePath> FileSystem::getSymLinkedDirectories(const FilePath& path)
|
||||
{
|
||||
return getSymLinkedDirectories(std::vector<FilePath>{path});
|
||||
}
|
||||
|
||||
std::set<FilePath> FileSystem::getSymLinkedDirectories(const std::vector<FilePath>& paths)
|
||||
{
|
||||
std::set<boost::filesystem::path> symlinkDirs;
|
||||
std::set<boost::filesystem::path> filePaths;
|
||||
|
||||
for (const FilePath& path: paths)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
static std::vector<FileInfo> getFileInfosFromPaths(
|
||||
const std::vector<FilePath>& paths, const std::vector<std::wstring>& fileExtensions, bool followSymLinks = true);
|
||||
|
||||
static std::set<FilePath> getSymLinkedDirectories(const FilePath& path);
|
||||
static std::set<FilePath> getSymLinkedDirectories(const std::vector<FilePath>& paths);
|
||||
|
||||
static unsigned long long getFileByteSize(const FilePath& filePath);
|
||||
|
||||
@@ -67,6 +67,9 @@ namespace utility
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
|
||||
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer);
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::string> toStrings(const std::vector<T>& d);
|
||||
template<>
|
||||
@@ -239,6 +242,17 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
|
||||
return targetContainer;
|
||||
}
|
||||
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceContainer)
|
||||
{
|
||||
std::vector<TargetType> targetContainer;
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.push_back(TargetType(sourceElement));
|
||||
}
|
||||
return targetContainer;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::string> utility::toStrings(const std::vector<T>& d)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user