logic: add contained symlinked directories to indexed and excluded paths
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "settings/SourceGroupSettings.h"
|
#include "settings/SourceGroupSettings.h"
|
||||||
#include "utility/file/FileManager.h"
|
#include "utility/file/FileManager.h"
|
||||||
#include "utility/file/FilePath.h"
|
#include "utility/file/FilePath.h"
|
||||||
|
#include "utility/file/FileSystem.h"
|
||||||
|
|
||||||
SourceGroup::~SourceGroup()
|
SourceGroup::~SourceGroup()
|
||||||
{
|
{
|
||||||
@@ -28,8 +29,8 @@ void SourceGroup::fetchAllSourceFilePaths()
|
|||||||
m_sourceFilePathsToIndex.clear();
|
m_sourceFilePathsToIndex.clear();
|
||||||
FileManager fileManager;
|
FileManager fileManager;
|
||||||
fileManager.update(
|
fileManager.update(
|
||||||
getAllSourcePaths(),
|
getAllSourcePaths(),
|
||||||
getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute(),
|
getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute(),
|
||||||
getSourceGroupSettings()->getSourceExtensions()
|
getSourceGroupSettings()->getSourceExtensions()
|
||||||
);
|
);
|
||||||
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
|
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
|
std::set<FilePath> SourceGroup::getAllSourceFilePaths() const
|
||||||
{
|
{
|
||||||
return m_allSourceFilePaths;
|
return m_allSourceFilePaths;
|
||||||
@@ -55,3 +66,20 @@ std::set<FilePath> SourceGroup::getSourceFilePathsToIndex() const
|
|||||||
{
|
{
|
||||||
return m_sourceFilePathsToIndex;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,12 +33,17 @@ public:
|
|||||||
std::set<FilePath>* filesToIndex, bool fullRefresh) = 0;
|
std::set<FilePath>* filesToIndex, bool fullRefresh) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
std::set<FilePath> getIndexedPaths();
|
||||||
|
std::set<FilePath> getExcludedPaths();
|
||||||
|
|
||||||
std::set<FilePath> m_allSourceFilePaths;
|
std::set<FilePath> m_allSourceFilePaths;
|
||||||
std::set<FilePath> m_sourceFilePathsToIndex;
|
std::set<FilePath> m_sourceFilePathsToIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() = 0;
|
virtual std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() = 0;
|
||||||
virtual std::vector<FilePath> getAllSourcePaths() const = 0;
|
virtual std::vector<FilePath> getAllSourcePaths() const = 0;
|
||||||
|
|
||||||
|
std::set<FilePath> findAndAddSymlinkedDirectories(const std::vector<FilePath>& paths);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SOURCE_GROUP_H
|
#endif // SOURCE_GROUP_H
|
||||||
|
|||||||
@@ -138,6 +138,55 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
|||||||
return files;
|
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)
|
unsigned long long FileSystem::getFileByteSize(const FilePath& filePath)
|
||||||
{
|
{
|
||||||
return boost::filesystem::file_size(filePath.path());
|
return boost::filesystem::file_size(filePath.path());
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef FILE_SYSTEM_H
|
#ifndef FILE_SYSTEM_H
|
||||||
#define FILE_SYSTEM_H
|
#define FILE_SYSTEM_H
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -18,6 +19,8 @@ public:
|
|||||||
static std::vector<FileInfo> getFileInfosFromPaths(
|
static std::vector<FileInfo> getFileInfosFromPaths(
|
||||||
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions, bool followSymLinks = true);
|
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 unsigned long long getFileByteSize(const FilePath& filePath);
|
||||||
|
|
||||||
static TimeStamp getLastWriteTime(const FilePath& filePath);
|
static TimeStamp getLastWriteTime(const FilePath& filePath);
|
||||||
|
|||||||
@@ -72,23 +72,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
|
|||||||
std::vector<std::string> compilerFlags;
|
std::vector<std::string> compilerFlags;
|
||||||
utility::append(compilerFlags, m_settings->getCompilerFlags());
|
utility::append(compilerFlags, m_settings->getCompilerFlags());
|
||||||
|
|
||||||
std::set<FilePath> indexedPaths;
|
std::set<FilePath> indexedPaths = getIndexedPaths();
|
||||||
for (const FilePath& p : m_settings->getSourcePathsExpandedAndAbsolute())
|
std::set<FilePath> excludedPaths = getExcludedPaths();
|
||||||
{
|
|
||||||
if (p.exists())
|
|
||||||
{
|
|
||||||
indexedPaths.insert(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<FilePath> excludedPaths;
|
|
||||||
for (const FilePath& p: m_settings->getExcludePathsExpandedAndAbsolute())
|
|
||||||
{
|
|
||||||
if (p.exists())
|
|
||||||
{
|
|
||||||
excludedPaths.insert(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
||||||
|
|
||||||
|
|||||||
@@ -51,23 +51,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxEmpty::getIndexerComm
|
|||||||
|
|
||||||
utility::append(compilerFlags, m_settings->getCompilerFlags());
|
utility::append(compilerFlags, m_settings->getCompilerFlags());
|
||||||
|
|
||||||
std::set<FilePath> indexedPaths;
|
std::set<FilePath> indexedPaths = getIndexedPaths();
|
||||||
for (const FilePath& p : m_settings->getSourcePathsExpandedAndAbsolute())
|
std::set<FilePath> excludedPaths = getExcludedPaths();
|
||||||
{
|
|
||||||
if (p.exists())
|
|
||||||
{
|
|
||||||
indexedPaths.insert(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<FilePath> excludedPaths;
|
|
||||||
for (const FilePath& p: m_settings->getExcludePathsExpandedAndAbsolute())
|
|
||||||
{
|
|
||||||
if (p.exists())
|
|
||||||
{
|
|
||||||
excludedPaths.insert(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
||||||
|
|
||||||
|
|||||||
@@ -36,24 +36,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
|
|||||||
const std::string languageStandard = getSourceGroupSettingsJava()->getStandard();
|
const std::string languageStandard = getSourceGroupSettingsJava()->getStandard();
|
||||||
|
|
||||||
std::vector<FilePath> classPath = getClassPath();
|
std::vector<FilePath> classPath = getClassPath();
|
||||||
|
std::set<FilePath> indexedPaths = getIndexedPaths();
|
||||||
std::set<FilePath> indexedPaths;
|
std::set<FilePath> excludedPaths = getExcludedPaths();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,18 @@ public:
|
|||||||
#endif
|
#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()
|
void test_filesystem_finds_existing_files()
|
||||||
{
|
{
|
||||||
TS_ASSERT(FileSystem::exists(FilePath("data/FileSystemTestSuite")));
|
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);
|
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)
|
bool isInFileInfos(const std::vector<FileInfo>& infos, const std::string filename)
|
||||||
{
|
{
|
||||||
for (const FileInfo& info : infos)
|
for (const FileInfo& info : infos)
|
||||||
|
|||||||
Reference in New Issue
Block a user