From 505106d602caf0c2825d613f7bc7b1f9aad7527f Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 25 Mar 2021 15:10:35 +0000 Subject: [PATCH] Replace std::filesystem::canonical usage Unlike on Windows, it doesn't return the "true" case of a path on Linux when case folding is enabled. Using NormalizeFilename() is more consistent but theoretically less accurate, though all currently hardcoded plugins are known to use ASCII filenames so there is no practical downside. --- src/api/sorting/plugin_graph.cpp | 31 ++++++------------------------- src/tests/api/internals/main.cpp | 23 ----------------------- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index 63e23e1e..4521e87a 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -384,25 +384,13 @@ void PluginGraph::AddHardcodedPluginEdges(Game& game) { game.GetLoadOrderHandler()->GetImplicitlyActivePlugins(); auto logger = getLogger(); - std::set processedPluginPaths; + std::set processedPluginPaths; for (const auto& plugin : implicitlyActivePlugins) { - auto pluginPath = game.DataPath() / u8path(plugin); - - try { - processedPluginPaths.insert(std::filesystem::canonical(pluginPath)); - } catch (std::filesystem::filesystem_error& e) { - if (logger) { - logger->trace( - "Skipping adding hardcoded plugin edges for \"{}\" as its " - "canonical path could not be determined: {}", - plugin, - e.what()); - } - continue; - } + processedPluginPaths.insert(NormalizeFilename(plugin)); if (game.Type() == GameType::tes5 && - loot::equivalent(plugin, "update.esm")) { + loot::equivalent(game.DataPath() / u8path(plugin), + game.DataPath() / "update.esm")) { if (logger) { logger->trace( "Skipping adding hardcoded plugin edges for Update.esm as it does " @@ -425,19 +413,12 @@ void PluginGraph::AddHardcodedPluginEdges(Game& game) { vertex_it vit, vitend; for (tie(vit, vitend) = boost::vertices(graph_); vit != vitend; ++vit) { - auto& graphPlugin = graph_[*vit]; - - auto graphPluginPath = game.DataPath() / u8path(graphPlugin.GetName()); - if (!std::filesystem::exists(graphPluginPath)) { - graphPluginPath += ".ghost"; - } - - if (!std::filesystem::exists(graphPluginPath)) { + if (*vit == pluginVertex.value()) { continue; } if (processedPluginPaths.count( - std::filesystem::canonical(graphPluginPath)) == 0) { + NormalizeFilename(graph_[*vit].GetName())) == 0) { AddEdge(pluginVertex.value(), *vit, EdgeType::hardcoded); } } diff --git a/src/tests/api/internals/main.cpp b/src/tests/api/internals/main.cpp index d2082333..7c419dcb 100644 --- a/src/tests/api/internals/main.cpp +++ b/src/tests/api/internals/main.cpp @@ -251,29 +251,6 @@ TEST(Filesystem, equivalentShouldBeCaseSensitive) { } #endif -TEST(Filesystem, canonicalShouldRequireThatThePathExists) { - EXPECT_THROW(std::filesystem::canonical("license2"), std::filesystem::filesystem_error); -} - -#ifdef _WIN32 -TEST(Filesystem, canonicalShouldFoldCase) { - auto upper = std::filesystem::canonical("LICENSE"); - auto lower = std::filesystem::canonical("license"); - - EXPECT_EQ(lower, upper); -} -#else -TEST(Filesystem, canonicalShouldNotFoldCase) { - std::ofstream out("license"); - out.close(); - - auto upper = std::filesystem::canonical("LICENSE"); - auto lower = std::filesystem::canonical("license"); - - EXPECT_NE(lower, upper); -} -#endif - int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();