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.
This commit is contained in:
Oliver Hamlet
2021-03-25 15:10:35 +00:00
parent 1ba07141e4
commit 505106d602
2 changed files with 6 additions and 48 deletions
+6 -25
View File
@@ -384,25 +384,13 @@ void PluginGraph::AddHardcodedPluginEdges(Game& game) {
game.GetLoadOrderHandler()->GetImplicitlyActivePlugins();
auto logger = getLogger();
std::set<std::filesystem::path> processedPluginPaths;
std::set<std::string> 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);
}
}
-23
View File
@@ -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();