const char kWebWidgetRuntimeBinaryPath[] = "/usr/bin/web-widget-runtime";
const char kWRTPath[] = "/usr/bin/wrt";
+bool CreateSymlinkIfNotExists(const fs::path& target, const fs::path& link) {
+ std::error_code ec;
+ bool exists = fs::exists(link, ec);
+ if (exists && !ec) {
+ // check if the symlink points to the correct target
+ exists = fs::is_symlink(link, ec) && fs::read_symlink(link, ec) == target;
+ if (ec)
+ LOG(WARNING) << "Failed to check symlink status: " << ec.message();
+ }
+
+ // symlink already exists with correct target
+ if (exists)
+ return true;
+
+ common_installer::RemoveAll(link);
+ fs::create_symlink(target, link, ec);
+ if (ec) {
+ LOG(ERROR) << "Failed to create symlink: " << ec.message();
+ return false;
+ }
+
+ return true;
+}
+
} // namespace
namespace wgt {
service_app_type[service_info.id()] = service_info.type();
}
- std::error_code error;
for (application_x* app :
GListRange<application_x*>(context_->manifest_data.get()->application)) {
// filter out non-wgt apps as this step is run for hybrid backend too
return false;
exec_path /= fs::path(app->appid);
- common_installer::RemoveAll(exec_path);
-
+ bool r;
if (strcmp(app->component_type, "uiapp") == 0) {
- fs::create_symlink(fs::path(kWRTPath), exec_path, error);
+ r = CreateSymlinkIfNotExists(fs::path(kWRTPath), exec_path);
} else if (strcmp(app->component_type, "watchapp") == 0) {
- fs::create_symlink(fs::path(kWRTPath), exec_path, error);
+ r = CreateSymlinkIfNotExists(fs::path(kWRTPath), exec_path);
} else if (strcmp(app->component_type, "widgetapp") == 0) {
- fs::create_symlink(kWebWidgetRuntimeBinaryPath, exec_path, error);
+ r = CreateSymlinkIfNotExists(kWebWidgetRuntimeBinaryPath, exec_path);
} else if (service_app_type[app->appid] == "standalone") {
- fs::create_symlink(kWrtServiceBinaryPath, exec_path, error);
+ r = CreateSymlinkIfNotExists(kWrtServiceBinaryPath, exec_path);
} else {
- fs::create_symlink(kWrtServiceLauncherBinaryPath, exec_path, error);
+ r = CreateSymlinkIfNotExists(kWrtServiceLauncherBinaryPath, exec_path);
}
- if (error) {
- LOG(ERROR) << "Failed to set symbolic link "
- << error.message();
+ if (!r) {
+ LOG(ERROR) << "Failed to set symbolic link";
return false;
}
}