Skip to content

Commit 3268b29

Browse files
Fix a bug in hostpolicy initialization for nativehost
1 parent ff561f6 commit 3268b29

File tree

1 file changed

+42
-33
lines changed
  • src/installer/corehost/cli/hostpolicy

1 file changed

+42
-33
lines changed

src/installer/corehost/cli/hostpolicy/args.cpp

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,47 @@ bool parse_arguments(
102102
args);
103103
}
104104

105+
bool set_root_from_app(const pal::string_t& managed_application_path,
106+
arguments_t& args)
107+
{
108+
args.managed_application = managed_application_path;
109+
110+
if (args.managed_application.empty())
111+
{
112+
// Managed app being empty by itself is not a failure. Host may be initialized from a config file.
113+
assert(args.host_mode != host_mode_t::apphost);
114+
return true;
115+
}
116+
117+
if (bundle::info_t::is_single_file_bundle())
118+
{
119+
const bundle::runner_t* app = bundle::runner_t::app();
120+
args.app_root = app->base_path();
121+
122+
// Check for the main app within the bundle.
123+
// locate() sets args.managed_application to the full path of the app extracted to disk.
124+
pal::string_t managed_application_name = get_filename(managed_application_path);
125+
if (app->locate(managed_application_name, args.managed_application))
126+
{
127+
return true;
128+
}
129+
130+
trace::info(_X("Managed application [%s] not found in single-file bundle"), managed_application_name.c_str());
131+
132+
// If the main assembly is not found in the bundle, continue checking on disk
133+
// for very unlikely case where the main app.dll was itself excluded from the app bundle.
134+
return pal::realpath(&args.managed_application);
135+
}
136+
137+
if (pal::realpath(&args.managed_application))
138+
{
139+
args.app_root = get_directory(managed_application_path);
140+
return true;
141+
}
142+
143+
return false;
144+
}
145+
105146
bool init_arguments(
106147
const pal::string_t& managed_application_path,
107148
const host_startup_info_t& host_info,
@@ -116,39 +157,7 @@ bool init_arguments(
116157
args.host_path = host_info.host_path;
117158
args.additional_deps_serialized = additional_deps_serialized;
118159

119-
if (!managed_application_path.empty())
120-
{
121-
pal::string_t managed_application_name = get_filename(managed_application_path);
122-
if (bundle::info_t::is_single_file_bundle())
123-
{
124-
args.app_root = bundle::runner_t::app()->base_path();
125-
const bundle::runner_t* app = bundle::runner_t::app();
126-
127-
// Check for the main app within the bundle.
128-
if (!app->locate(managed_application_name, args.managed_application))
129-
{
130-
// If the main app is not found in the bundle, check beside the bundle
131-
// for very unlikely case where the main app.dll was itself excluded from the app bundle.
132-
args.managed_application = managed_application_path;
133-
if (!pal::realpath(&args.managed_application))
134-
{
135-
trace::error(_X("Failed to locate managed application [%s]"), args.managed_application.c_str());
136-
return false;
137-
}
138-
}
139-
}
140-
else
141-
{
142-
args.app_root = get_directory(managed_application_path);
143-
args.managed_application = managed_application_path;
144-
if (!pal::realpath(&args.managed_application))
145-
{
146-
trace::error(_X("Failed to locate managed application [%s]"), args.managed_application.c_str());
147-
return false;
148-
}
149-
}
150-
}
151-
else
160+
if (!set_root_from_app(managed_application_path, args))
152161
{
153162
trace::error(_X("Failed to locate managed application [%s]"), args.managed_application.c_str());
154163
return false;

0 commit comments

Comments
 (0)