1 /* 2014, Copyright © Eurogiciel Coporation, APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
6 #include "wgt/step/filesystem/step_create_symbolic_link.h"
8 #include <pkgmgr-info.h>
11 #include <boost/filesystem.hpp>
12 #include <boost/system/error_code.hpp>
13 #include <common/utils/file_util.h>
14 #include <common/utils/glist_range.h>
20 namespace bf = boost::filesystem;
21 namespace bs = boost::system;
25 const char kWrtServiceBinaryPath[] = "/usr/bin/wrt-service";
26 const char kWebWidgetRuntimeBinaryPath[] = "/usr/bin/web-widget-runtime";
31 namespace filesystem {
33 bool StepCreateSymbolicLink::CreateSymlinksForApps() {
34 boost::system::error_code error;
35 for (application_x* app :
36 GListRange<application_x*>(context_->manifest_data.get()->application)) {
37 // filter out non-wgt apps as this step is run for hybrid backend too
38 if (strcmp("webapp", app->type) != 0)
40 // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
41 bf::path exec_path = context_->pkg_path.get() / bf::path("bin");
42 common_installer::CreateDir(exec_path);
44 exec_path /= bf::path(app->appid);
45 if (bf::exists(exec_path))
46 bf::remove_all(exec_path);
48 if (strcmp(app->component_type, "uiapp") == 0) {
49 bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error);
50 } else if (strcmp(app->component_type, "watchapp") == 0) {
51 bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error);
52 } else if (strcmp(app->component_type, "widgetapp") == 0) {
53 bf::create_symlink(kWebWidgetRuntimeBinaryPath, exec_path, error);
55 bf::create_symlink(kWrtServiceBinaryPath, exec_path, error);
58 LOG(ERROR) << "Failed to set symbolic link "
59 << boost::system::system_error(error).what();
66 common_installer::Step::Status StepCreateSymbolicLink::process() {
67 assert(context_->manifest_data.get());
69 if (!CreateSymlinksForApps())
70 return Status::APP_DIR_ERROR;
72 LOG(DEBUG) << "Symlinks created successfully";
76 common_installer::Step::Status StepCreateSymbolicLink::undo() {
77 for (application_x* app :
78 GListRange<application_x*>(context_->manifest_data.get()->application)) {
79 bf::path exec_path = context_->pkg_path.get() / "bin" / app->appid;
80 if (bf::exists(exec_path))
81 bf::remove_all(exec_path);
86 } // namespace filesystem