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";
27 const char kWRTPath[] = "/usr/bin/wrt";
32 namespace filesystem {
34 bool StepCreateSymbolicLink::CreateSymlinksForApps() {
35 boost::system::error_code error;
36 for (application_x* app :
37 GListRange<application_x*>(context_->manifest_data.get()->application)) {
38 // filter out non-wgt apps as this step is run for hybrid backend too
39 if (strcmp("webapp", app->type) != 0)
41 // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
42 bf::path exec_path = context_->GetPkgPath() / bf::path("bin");
43 common_installer::CreateDir(exec_path);
45 exec_path /= bf::path(app->appid);
46 common_installer::RemoveAll(exec_path);
48 if (strcmp(app->component_type, "uiapp") == 0) {
49 bf::create_symlink(bf::path(kWRTPath), exec_path, error);
50 } else if (strcmp(app->component_type, "watchapp") == 0) {
51 bf::create_symlink(bf::path(kWRTPath), 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_->GetPkgPath() / "bin" / app->appid;
80 common_installer::RemoveAll(exec_path);
85 } // namespace filesystem