diff --git a/bin/test/data/FilePathTestSuite/parent/target b/bin/test/data/FilePathTestSuite/parent/target new file mode 120000 index 00000000..78bc3372 --- /dev/null +++ b/bin/test/data/FilePathTestSuite/parent/target @@ -0,0 +1 @@ +../target \ No newline at end of file diff --git a/bin/test/data/FilePathTestSuite/target/d.cpp b/bin/test/data/FilePathTestSuite/target/d.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/app/main.cpp b/src/app/main.cpp index 05b6fa3c..78f9e993 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -222,6 +222,22 @@ int main(int argc, char *argv[]) QScopedPointer networkFactory; QScopedPointer viewFactory; + if (!commandLineParser.runWithoutGUI()) + { + qtApp->setAttribute(Qt::AA_UseHighDpiPixmaps); + + utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); + utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf"); + + networkFactory.reset(new QtNetworkFactory()); + viewFactory.reset(new QtViewFactory()); + } + + Application::createInstance(version, viewFactory.data(), networkFactory.data()); + + ScopedFunctor f([](){ + Application::destroyInstance(); + }); if (commandLineParser.runWithoutGUI()) { @@ -235,23 +251,6 @@ int main(int argc, char *argv[]) return 0; } } - else - { - qtApp->setAttribute(Qt::AA_UseHighDpiPixmaps); - - utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); - utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf"); - - networkFactory.reset(new QtNetworkFactory()); - viewFactory.reset(new QtViewFactory()); - } - - - Application::createInstance(version, viewFactory.data(), networkFactory.data()); - - ScopedFunctor f([](){ - Application::destroyInstance(); - }); prefillPaths(); addLanguageModules(); diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp index 94c3e18e..b3d84575 100644 --- a/src/lib/data/indexer/TaskBuildIndex.cpp +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -271,17 +271,11 @@ void TaskBuildIndex::updateIndexingDialog( if (!sourcePath.empty()) { std::stringstream ss; - ss << "[" << m_indexingFileCount - << "/" << sourceFileCount - << "] Indexing file: "; - ss << sourcePath.str(); + ss << "[" << m_indexingFileCount << "/" << sourceFileCount << "] Indexing file: " << sourcePath.str(); MessageStatus(ss.str(), false, true).dispatch(); } - if (std::shared_ptr dialogView = Application::getInstance()->getDialogView()) - { - dialogView->updateIndexingDialog( - m_indexingFileCount, indexedSourceFileCount, sourceFileCount, sourcePath.str() - ); - } + Application::getInstance()->getDialogView()->updateIndexingDialog( + m_indexingFileCount, indexedSourceFileCount, sourceFileCount, sourcePath.str() + ); } diff --git a/src/lib/utility/commandline/commands/CommandlineCommand.cpp b/src/lib/utility/commandline/commands/CommandlineCommand.cpp index f64d78f8..b5e2ed4c 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommand.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommand.cpp @@ -11,6 +11,10 @@ Command::Command(const std::string name, CommandLineParser* parser) { } +Command::~Command() +{ +} + const std::string Command::name() { return m_name; @@ -32,5 +36,4 @@ void Command::printHelp() } } - } // namespace cmd diff --git a/src/lib/utility/commandline/commands/CommandlineCommand.h b/src/lib/utility/commandline/commands/CommandlineCommand.h index 290a27e8..5a92a649 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommand.h +++ b/src/lib/utility/commandline/commands/CommandlineCommand.h @@ -8,13 +8,15 @@ namespace po = boost::program_options; namespace commandline { + enum class ReturnStatus; class CommandLineParser; - -class Command { +class Command +{ public: Command(const std::string name, CommandLineParser* parser = nullptr); + virtual ~Command(); const std::string name(); diff --git a/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp b/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp index b4f23055..d44dcdf6 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp @@ -83,6 +83,10 @@ CommandConfig::CommandConfig(CommandLineParser* parser) { } +CommandConfig::~CommandConfig() +{ +} + void CommandConfig::setup() { po::options_description options("Config Options"); @@ -112,7 +116,7 @@ void CommandConfig::setup() m_options.add(options); } -void printVector(std::string title, std::vector vec) +void printVector(const std::string& title, const std::vector& vec) { std::cout << "\n " << title << ":"; if (vec.empty()) @@ -125,17 +129,8 @@ void printVector(std::string title, std::vector vec) } } -void CommandConfig::printSettings() +void CommandConfig::printSettings(ApplicationSettings* settings) { - ApplicationSettings* settings = ApplicationSettings::getInstance().get(); - settings->load(UserPaths::getAppSettingsPath()); - - if (settings == nullptr) - { - LOG_ERROR("Could not load application settings"); - return; - } - std::cout << "Sourcetrail Settings:\n" << "\n indexerthread count: " << settings->getIndexerThreadCount() << "\n use-processes: " << settings->getMultiProcessIndexingEnabled() @@ -144,9 +139,9 @@ void CommandConfig::printSettings() << "\n jvm-path: " << settings->getJavaPath() << "\n jvm-max-memory: " << settings->getJavaMaximumMemory() << "\n maven-path: " << settings->getMavenPath().str(); - printVector("global-header-search-paths", std::move(settings->getHeaderSearchPaths())); - printVector("global-framework-search-paths", std::move(settings->getFrameworkSearchPaths())); - printVector("jre-system-library-paths", std::move(settings->getJreSystemLibraryPaths())); + printVector("global-header-search-paths", settings->getHeaderSearchPaths()); + printVector("global-framework-search-paths", settings->getFrameworkSearchPaths()); + printVector("jre-system-library-paths", settings->getJreSystemLibraryPaths()); License license; license.loadFromEncodedString(settings->getLicenseString(), AppPath::getAppPath()); std::cout << "\nValid license: " << license.isValid() << std::endl; @@ -178,14 +173,18 @@ ReturnStatus CommandConfig::parse(std::vector& args) return ReturnStatus::CMD_QUIT; } - if (args[0] == "show" || vm.count("show")) + ApplicationSettings* settings = ApplicationSettings::getInstance().get(); + if (settings == nullptr) { - printSettings(); + LOG_ERROR("No application settings loaded"); return ReturnStatus::CMD_QUIT; } - ApplicationSettings* settings = ApplicationSettings::getInstance().get(); - settings->load(UserPaths::getAppSettingsPath()); + if (args[0] == "show" || vm.count("show")) + { + printSettings(settings); + return ReturnStatus::CMD_QUIT; + } parseAndSetValue(&ApplicationSettings::setMultiProcessIndexingEnabled, "use-processes", settings, vm); parseAndSetValue(&ApplicationSettings::setLoggingEnabled, "logging-enabled", settings, vm); diff --git a/src/lib/utility/commandline/commands/CommandlineCommandConfig.h b/src/lib/utility/commandline/commands/CommandlineCommandConfig.h index 8f07bd4e..cc3e4648 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandConfig.h +++ b/src/lib/utility/commandline/commands/CommandlineCommandConfig.h @@ -5,21 +5,25 @@ #include #include "utility/commandline/commands/CommandlineCommand.h" +class ApplicationSettings; class CommandLineParser; namespace commandline { enum class ReturnStatus; -class CommandConfig : public Command { +class CommandConfig + : public Command +{ public: CommandConfig(CommandLineParser* parser); + virtual ~CommandConfig(); virtual void setup(); virtual ReturnStatus parse(std::vector& args); -private: - void printSettings(); +private: + void printSettings(ApplicationSettings* settings); }; } // namespace cmd diff --git a/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp b/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp index 3ca9df61..5738767e 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp @@ -11,6 +11,10 @@ CommandIndex::CommandIndex(CommandLineParser* parser) { } +CommandIndex::~CommandIndex() +{ +} + void CommandIndex::setup() { po::options_description options("Config Options"); diff --git a/src/lib/utility/commandline/commands/CommandlineCommandIndex.h b/src/lib/utility/commandline/commands/CommandlineCommandIndex.h index f3e084da..cb5d5462 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandIndex.h +++ b/src/lib/utility/commandline/commands/CommandlineCommandIndex.h @@ -2,6 +2,7 @@ #define COMMANDLINE_COMMAND_INDEX_H #include + #include "boost/program_options.hpp" #include "utility/commandline/commands/CommandlineCommand.h" @@ -12,9 +13,12 @@ namespace commandline { enum class ReturnStatus; -class CommandIndex : public Command { +class CommandIndex + : public Command +{ public: CommandIndex(CommandLineParser* parser); + virtual ~CommandIndex(); virtual void setup(); virtual ReturnStatus parse(std::vector& args); diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index bf56d286..07c37500 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -120,61 +120,45 @@ FilePath FilePath::absolute() const FilePath FilePath::canonical() const { - if (m_canonicalized) + if (m_canonicalized || !exists()) { return FilePath(*this); } - if (!exists()) - { - return FilePath(*this); - } - - boost::filesystem::path abs_p = boost::filesystem::absolute(m_path); boost::filesystem::path canonicalPath; + +#if defined(_WIN32) + boost::filesystem::path abs_p = boost::filesystem::absolute(m_path); for (boost::filesystem::path::iterator it = abs_p.begin(); it != abs_p.end(); ++it) { if (*it == "..") { - // /a/b/.. is not necessarily /a if b is a symbolic link - if (boost::filesystem::is_symlink(canonicalPath)) - { - canonicalPath /= *it; - } - // /a/b/../.. is not /a/b/.. under most circumstances - // We can end up with ..s in our result because of symbolic links - else if (canonicalPath.filename() == "..") - { - canonicalPath /= *it; - } - // Otherwise it should be safe to resolve the parent - else - { - canonicalPath = canonicalPath.parent_path(); - } + canonicalPath = canonicalPath.parent_path(); } else if (*it == ".") { - // Ignore + continue; } else { - // Just cat other path entries canonicalPath /= *it; - } - if (boost::filesystem::is_symlink(canonicalPath)) - { - boost::filesystem::path symlink = boost::filesystem::read_symlink(canonicalPath); - if (!symlink.empty()) + if (boost::filesystem::is_symlink(canonicalPath)) { - // on Windows the read_symlink function discards the drive letter (this is a boost bug). Therefore - // we need to make the path absolute again. We also have to discard the trailing \0 characters so - // that we can continue appending to the path. - canonicalPath = utility::substrBeforeFirst(boost::filesystem::absolute(symlink).string(), '\0'); + boost::filesystem::path symlink = boost::filesystem::read_symlink(canonicalPath); + if (!symlink.empty()) + { + // on Windows the read_symlink function discards the drive letter (this is a boost bug). Therefore + // we need to make the path absolute again. We also have to discard the trailing \0 characters so + // that we can continue appending to the path. + canonicalPath = utility::substrBeforeFirst(boost::filesystem::absolute(symlink).string(), '\0'); + } } } } +#else + canonicalPath = boost::filesystem::canonical(m_path); +#endif FilePath ret(canonicalPath); ret.m_canonicalized = true; diff --git a/src/test/FilePathTestSuite.h b/src/test/FilePathTestSuite.h index 43e62bac..75a2434b 100644 --- a/src/test/FilePathTestSuite.h +++ b/src/test/FilePathTestSuite.h @@ -170,6 +170,16 @@ public: TS_ASSERT_EQUALS(path.absolute(), path.canonical()); } + void test_file_path_canonical_removes_symlinks() + { +#ifndef _WIN32 + FilePath pathA("data/FilePathTestSuite/parent/target/d.cpp"); + FilePath pathB("data/FilePathTestSuite/target/d.cpp"); + + TS_ASSERT_EQUALS(pathB.absolute(), pathA.canonical()); +#endif + } + void test_file_path_compares_paths_with_posix_and_windows_format() { #ifdef _WIN32 diff --git a/src/test/TestSuiteFixture.cpp b/src/test/TestSuiteFixture.cpp index eff3f4bc..f528021a 100644 --- a/src/test/TestSuiteFixture.cpp +++ b/src/test/TestSuiteFixture.cpp @@ -1,6 +1,6 @@ #include "TestSuiteFixture.h" -#include +#include #include "utility/logging/FileLogger.h" #include "utility/logging/LogManager.h" @@ -15,8 +15,6 @@ TestSuiteFixture::~TestSuiteFixture() { } -#include - bool TestSuiteFixture::setUpWorld() { LogManager* logManager = LogManager::getInstance().get();