Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitek Karas <vitek.karas@microsoft.com>2021-09-22 20:04:00 +0300
committerEric StJohn <ericstj@microsoft.com>2021-09-22 20:07:51 +0300
commit20bfd6a8903e47c7cd68fd1562bfffdb6c5b76c3 (patch)
tree80fe3861a118e9549b226e73a362eb949e7ae53b /src/native
parentb700018f8abb67c9b76379ca6f1da8a53b7127a6 (diff)
Split install_location to file-per-architecture (#59404)
On non-Windows we used install_location file with multiple lines which contained locations per-architecture (and the default). This changes the host to use separate file for each architecture: * `install_location_<arch>` for the architecture specific * `install_location` for the "legacy" file This is a much easier format for installers to handle (and it also simplifies the apphost code a little bit). Adapted tests to the new behavior. Removed some tests which don't make sense anymore. Some small test cleanup to deduplicate code. Changed the test-only env. variable to point to the directory with configuration files instead of to the configuration file itself.
Diffstat (limited to 'src/native')
-rw-r--r--src/native/corehost/hostmisc/pal.unix.cpp108
1 files changed, 52 insertions, 56 deletions
diff --git a/src/native/corehost/hostmisc/pal.unix.cpp b/src/native/corehost/hostmisc/pal.unix.cpp
index ef644bdf0d7..1ea7817900c 100644
--- a/src/native/corehost/hostmisc/pal.unix.cpp
+++ b/src/native/corehost/hostmisc/pal.unix.cpp
@@ -383,12 +383,12 @@ pal::string_t pal::get_dotnet_self_registered_config_location()
{
// ***Used only for testing***
pal::string_t environment_install_location_override;
- if (test_only_getenv(_X("_DOTNET_TEST_INSTALL_LOCATION_FILE_PATH"), &environment_install_location_override))
+ if (test_only_getenv(_X("_DOTNET_TEST_INSTALL_LOCATION_PATH"), &environment_install_location_override))
{
return environment_install_location_override;
}
- return _X("/etc/dotnet/install_location");
+ return _X("/etc/dotnet");
}
namespace
@@ -414,6 +414,42 @@ namespace
}
}
+bool get_install_location_from_file(const pal::string_t& file_path, bool& file_found, pal::string_t& install_location)
+{
+ file_found = true;
+ bool install_location_found = false;
+ FILE* install_location_file = pal::file_open(file_path, "r");
+ if (install_location_file != nullptr)
+ {
+ if (!get_line_from_file(install_location_file, install_location))
+ {
+ trace::warning(_X("Did not find any install location in '%s'."), file_path.c_str());
+ }
+ else
+ {
+ install_location_found = true;
+ }
+
+ fclose(install_location_file);
+ if (install_location_found)
+ return true;
+ }
+ else
+ {
+ if (errno == ENOENT)
+ {
+ trace::verbose(_X("The install_location file ['%s'] does not exist - skipping."), file_path.c_str());
+ file_found = false;
+ }
+ else
+ {
+ trace::error(_X("The install_location file ['%s'] failed to open: %s."), file_path.c_str(), pal::strerror(errno));
+ }
+ }
+
+ return false;
+}
+
bool pal::get_dotnet_self_registered_dir(pal::string_t* recv)
{
recv->clear();
@@ -427,71 +463,31 @@ bool pal::get_dotnet_self_registered_dir(pal::string_t* recv)
}
// ***************************
- pal::string_t install_location_file_path = get_dotnet_self_registered_config_location();
- trace::verbose(_X("Looking for install_location file in '%s'."), install_location_file_path.c_str());
- FILE* install_location_file = pal::file_open(install_location_file_path, "r");
- if (install_location_file == nullptr)
- {
- if (errno == ENOENT)
- {
- trace::verbose(_X("The install_location file ['%s'] does not exist - skipping."), install_location_file_path.c_str());
- }
- else
- {
- trace::error(_X("The install_location file ['%s'] failed to open: %s."), install_location_file_path.c_str(), pal::strerror(errno));
- }
-
- return false;
- }
+ pal::string_t install_location_path = get_dotnet_self_registered_config_location();
+ pal::string_t arch_specific_install_location_file_path = install_location_path;
+ append_path(&arch_specific_install_location_file_path, (_X("install_location_") + to_lower(get_arch())).c_str());
+ trace::verbose(_X("Looking for architecture specific install_location file in '%s'."), arch_specific_install_location_file_path.c_str());
pal::string_t install_location;
- int current_line = 0;
- bool is_first_line = true, install_location_found = false;
-
- while (get_line_from_file(install_location_file, install_location))
+ bool file_found = false;
+ if (!get_install_location_from_file(arch_specific_install_location_file_path, file_found, install_location))
{
- current_line++;
- size_t arch_sep = install_location.find(_X('='));
- if (arch_sep == pal::string_t::npos)
+ if (file_found)
{
- if (is_first_line)
- {
- recv->assign(install_location);
- install_location_found = true;
- trace::verbose(_X("Found install location path '%s'."), install_location.c_str());
- }
- else
- {
- trace::warning(_X("Found unprefixed install location path '%s' on line %d."), install_location.c_str(), current_line);
- trace::warning(_X("Only the first line in '%s' may not have an architecture prefix."), install_location_file_path.c_str());
- }
-
- is_first_line = false;
- continue;
+ return false;
}
- pal::string_t arch_prefix = install_location.substr(0, arch_sep);
- pal::string_t path_to_location = install_location.substr(arch_sep + 1);
+ pal::string_t legacy_install_location_file_path = install_location_path;
+ append_path(&legacy_install_location_file_path, _X("install_location"));
+ trace::verbose(_X("Looking for install_location file in '%s'."), legacy_install_location_file_path.c_str());
- trace::verbose(_X("Found architecture-specific install location path: '%s' ('%s')."), path_to_location.c_str(), arch_prefix.c_str());
- if (pal::strcasecmp(arch_prefix.c_str(), get_arch()) == 0)
+ if (!get_install_location_from_file(legacy_install_location_file_path, file_found, install_location))
{
- recv->assign(path_to_location);
- install_location_found = true;
- trace::verbose(_X("Found architecture-specific install location path matching the current host architecture ('%s'): '%s'."), arch_prefix.c_str(), path_to_location.c_str());
- break;
+ return false;
}
-
- is_first_line = false;
- }
-
- fclose(install_location_file);
- if (!install_location_found)
- {
- trace::warning(_X("Did not find any install location in '%s'."), install_location_file_path.c_str());
- return false;
}
+ recv->assign(install_location);
trace::verbose(_X("Using install location '%s'."), recv->c_str());
return true;
}