Avoid extra search of multilevel dir when it is the same as dotnet root (dotnet/core...
authorSteve Harter <steveharter@users.noreply.github.com>
Mon, 13 Aug 2018 22:04:14 +0000 (17:04 -0500)
committerGitHub <noreply@github.com>
Mon, 13 Aug 2018 22:04:14 +0000 (17:04 -0500)
Commit migrated from https://github.com/dotnet/core-setup/commit/b17186ff80b6f58c15ee7dd474a719697c8dea10

src/installer/corehost/cli/fxr/framework_info.cpp
src/installer/corehost/cli/fxr/fx_muxer.cpp
src/installer/corehost/cli/fxr/sdk_info.cpp
src/installer/corehost/cli/fxr/sdk_resolver.cpp
src/installer/corehost/common/pal.h
src/installer/corehost/common/pal.unix.cpp
src/installer/corehost/common/pal.windows.cpp

index c6d5cf9..e4de608 100644 (file)
@@ -49,7 +49,7 @@ bool compare_by_name_and_version(const framework_info &a, const framework_info &
     {
         for (pal::string_t dir : global_dirs)
         {
-            if (dir != own_dir_temp)
+            if (!pal::are_paths_equal_with_normalized_casing(dir, own_dir_temp))
             {
                 hive_dir.push_back(dir);
             }
index 2821691..27bda32 100644 (file)
@@ -509,7 +509,7 @@ fx_definition_t* fx_muxer_t::resolve_fx(
         for (pal::string_t dir : global_dirs)
         {
             // Avoid duplicate of dotnet_dir_temp
-            if (dir != dotnet_dir_temp)
+            if (!pal::are_paths_equal_with_normalized_casing(dir, dotnet_dir_temp))
             {
                 hive_dir.push_back(dir);
             }
index 4732b2a..dc93def 100644 (file)
@@ -30,7 +30,7 @@ void sdk_info::get_all_sdk_infos(
     {
         for (pal::string_t dir : global_dirs)
         {
-            if (dir != own_dir_temp)
+            if (!pal::are_paths_equal_with_normalized_casing(dir, own_dir_temp))
             {
                 hive_dir.push_back(dir);
             }
index 32cfdf0..3e7c3d6 100644 (file)
@@ -179,16 +179,24 @@ bool sdk_resolver_t::resolve_sdk_dotnet_path(const pal::string_t& dotnet_root, c
     std::vector<pal::string_t> global_dirs;
     bool multilevel_lookup = multilevel_lookup_enabled();
 
+    pal::string_t dotnet_root_temp;
     if (!dotnet_root.empty())
     {
-        hive_dir.push_back(dotnet_root);
+        // dotnet_root contains DIR_SEPARATOR appended that we need to remove.
+        dotnet_root_temp = dotnet_root;
+        remove_trailing_dir_seperator(&dotnet_root_temp);
+        hive_dir.push_back(dotnet_root_temp);
     }
 
     if (multilevel_lookup && pal::get_global_dotnet_dirs(&global_dirs))
     {
         for (pal::string_t dir : global_dirs)
         {
-            hive_dir.push_back(dir);
+            // Avoid duplicate of dotnet_root_temp
+            if (!pal::are_paths_equal_with_normalized_casing(dir, dotnet_root_temp))
+            {
+                hive_dir.push_back(dir);
+            }
         }
     }
 
index 71c7fa4..bd4ca67 100644 (file)
@@ -228,6 +228,8 @@ namespace pal
     void unload_library(dll_t library);
 
     bool is_running_in_wow64();
+
+    bool are_paths_equal_with_normalized_casing(const string_t& path1, const string_t& path2);
 }
 
 #endif // PAL_H
index 3ccafd7..9273c80 100644 (file)
@@ -641,3 +641,14 @@ bool pal::is_running_in_wow64()
 {
     return false;
 }
+
+bool pal::are_paths_equal_with_normalized_casing(const string_t& path1, const string_t& path2)
+{
+#if defined(__APPLE__)
+    // On Mac, paths are case-insensitive
+    return (strcasecmp(path1.c_str(), path2.c_str()) == 0);
+#else
+    // On Linux, paths are case-sensitive
+    return path1 == path2;
+#endif
+}
index 3ec53ea..6b085ea 100644 (file)
@@ -519,3 +519,9 @@ bool pal::is_running_in_wow64()
     }
     return (fWow64Process != FALSE);
 }
+
+bool pal::are_paths_equal_with_normalized_casing(const string_t& path1, const string_t& path2)
+{
+    // On Windows, paths are case-insensitive
+    return (strcasecmp(path1.c_str(), path2.c_str()) == 0);
+}