logic: add contained symlinked directories to indexed and excluded paths

This commit is contained in:
Eberhard Graether
2017-11-07 13:43:50 +01:00
parent 28fe1533b7
commit a2d412ccfa
8 changed files with 110 additions and 54 deletions
+30 -2
View File
@@ -3,6 +3,7 @@
#include "settings/SourceGroupSettings.h"
#include "utility/file/FileManager.h"
#include "utility/file/FilePath.h"
#include "utility/file/FileSystem.h"
SourceGroup::~SourceGroup()
{
@@ -28,8 +29,8 @@ void SourceGroup::fetchAllSourceFilePaths()
m_sourceFilePathsToIndex.clear();
FileManager fileManager;
fileManager.update(
getAllSourcePaths(),
getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute(),
getAllSourcePaths(),
getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute(),
getSourceGroupSettings()->getSourceExtensions()
);
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
@@ -46,6 +47,16 @@ void SourceGroup::fetchSourceFilePathsToIndex(const std::set<FilePath>& staticSo
}
}
std::set<FilePath> SourceGroup::getIndexedPaths()
{
return findAndAddSymlinkedDirectories(getSourceGroupSettings()->getSourcePathsExpandedAndAbsolute());
}
std::set<FilePath> SourceGroup::getExcludedPaths()
{
return findAndAddSymlinkedDirectories(getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute());
}
std::set<FilePath> SourceGroup::getAllSourceFilePaths() const
{
return m_allSourceFilePaths;
@@ -55,3 +66,20 @@ std::set<FilePath> SourceGroup::getSourceFilePathsToIndex() const
{
return m_sourceFilePathsToIndex;
}
std::set<FilePath> SourceGroup::findAndAddSymlinkedDirectories(const std::vector<FilePath>& paths)
{
std::set<FilePath> resultPaths;
for (const FilePath& path: paths)
{
if (path.exists())
{
resultPaths.insert(path);
}
}
std::set<FilePath> symLinkPaths = FileSystem::getSymLinkedDirectories(paths);
resultPaths.insert(symLinkPaths.begin(), symLinkPaths.end());
return resultPaths;
}
+5
View File
@@ -33,12 +33,17 @@ public:
std::set<FilePath>* filesToIndex, bool fullRefresh) = 0;
protected:
std::set<FilePath> getIndexedPaths();
std::set<FilePath> getExcludedPaths();
std::set<FilePath> m_allSourceFilePaths;
std::set<FilePath> m_sourceFilePathsToIndex;
private:
virtual std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() = 0;
virtual std::vector<FilePath> getAllSourcePaths() const = 0;
std::set<FilePath> findAndAddSymlinkedDirectories(const std::vector<FilePath>& paths);
};
#endif // SOURCE_GROUP_H
+49
View File
@@ -138,6 +138,55 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
return files;
}
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)
{
if (path.isDirectory())
{
boost::filesystem::recursive_directory_iterator it(path.path(), boost::filesystem::symlink_option::recurse);
boost::filesystem::recursive_directory_iterator endit;
boost::system::error_code ec;
for ( ; it != endit ; it.increment(ec) )
{
if (boost::filesystem::is_symlink(*it))
{
// check for self-referencing symlinks
boost::filesystem::path p = boost::filesystem::read_symlink(*it);
if (p.filename() == p.string() && p.filename() == it->path().filename())
{
continue;
}
// check for duplicates when following directory symlinks
if (boost::filesystem::is_directory(*it))
{
boost::filesystem::path absDir = boost::filesystem::canonical(p, it->path().parent_path());
if (symlinkDirs.find(absDir) != symlinkDirs.end())
{
it.no_push();
continue;
}
symlinkDirs.insert(absDir);
}
}
}
}
}
std::set<FilePath> files;
for (auto& p : symlinkDirs)
{
files.insert(FilePath(p));
}
return files;
}
unsigned long long FileSystem::getFileByteSize(const FilePath& filePath)
{
return boost::filesystem::file_size(filePath.path());
+3
View File
@@ -1,6 +1,7 @@
#ifndef FILE_SYSTEM_H
#define FILE_SYSTEM_H
#include <set>
#include <string>
#include <vector>
@@ -18,6 +19,8 @@ public:
static std::vector<FileInfo> getFileInfosFromPaths(
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions, bool followSymLinks = true);
static std::set<FilePath> getSymLinkedDirectories(const std::vector<FilePath>& paths);
static unsigned long long getFileByteSize(const FilePath& filePath);
static TimeStamp getLastWriteTime(const FilePath& filePath);
+2 -17
View File
@@ -72,23 +72,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
std::vector<std::string> compilerFlags;
utility::append(compilerFlags, m_settings->getCompilerFlags());
std::set<FilePath> indexedPaths;
for (const FilePath& p : m_settings->getSourcePathsExpandedAndAbsolute())
{
if (p.exists())
{
indexedPaths.insert(p);
}
}
std::set<FilePath> excludedPaths;
for (const FilePath& p: m_settings->getExcludePathsExpandedAndAbsolute())
{
if (p.exists())
{
excludedPaths.insert(p);
}
}
std::set<FilePath> indexedPaths = getIndexedPaths();
std::set<FilePath> excludedPaths = getExcludedPaths();
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
+2 -17
View File
@@ -51,23 +51,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxEmpty::getIndexerComm
utility::append(compilerFlags, m_settings->getCompilerFlags());
std::set<FilePath> indexedPaths;
for (const FilePath& p : m_settings->getSourcePathsExpandedAndAbsolute())
{
if (p.exists())
{
indexedPaths.insert(p);
}
}
std::set<FilePath> excludedPaths;
for (const FilePath& p: m_settings->getExcludePathsExpandedAndAbsolute())
{
if (p.exists())
{
excludedPaths.insert(p);
}
}
std::set<FilePath> indexedPaths = getIndexedPaths();
std::set<FilePath> excludedPaths = getExcludedPaths();
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
+2 -18
View File
@@ -36,24 +36,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
const std::string languageStandard = getSourceGroupSettingsJava()->getStandard();
std::vector<FilePath> classPath = getClassPath();
std::set<FilePath> indexedPaths;
for (const FilePath& p: getSourceGroupSettings()->getSourcePathsExpandedAndAbsolute())
{
if (p.exists())
{
indexedPaths.insert(p);
}
}
std::set<FilePath> excludedPaths;
for (const FilePath& p: getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute())
{
if (p.exists())
{
excludedPaths.insert(p);
}
}
std::set<FilePath> indexedPaths = getIndexedPaths();
std::set<FilePath> excludedPaths = getExcludedPaths();
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
+17
View File
@@ -109,6 +109,18 @@ public:
#endif
}
void test_find_symlinked_directories()
{
#ifndef _WIN32
std::vector<FilePath> directoryPaths;
directoryPaths.push_back(FilePath("./data/FileSystemTestSuite/src"));
std::set<FilePath> dirs = FileSystem::getSymLinkedDirectories(directoryPaths);
TS_ASSERT_EQUALS(dirs.size(), 2);
#endif
}
void test_filesystem_finds_existing_files()
{
TS_ASSERT(FileSystem::exists(FilePath("data/FileSystemTestSuite")));
@@ -145,6 +157,11 @@ private:
return std::end(files) != std::find(std::begin(files), std::end(files), filename);
}
bool isInFiles(const std::set<FilePath>& files, const FilePath& filename)
{
return std::end(files) != files.find(filename);
}
bool isInFileInfos(const std::vector<FileInfo>& infos, const std::string filename)
{
for (const FileInfo& info : infos)