Use GList in manifest_x structures
[platform/core/appfw/app-installers.git] / src / wgt / step / step_create_symbolic_link.cc
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.
5
6 #include "wgt/step/step_create_symbolic_link.h"
7
8 #include <pkgmgr-info.h>
9 #include <unistd.h>
10
11 #include <boost/filesystem.hpp>
12 #include <cassert>
13 #include <cstring>
14 #include <cstdio>
15 #include <string>
16
17 #include "common/utils/file_util.h"
18 #include "common/utils/glist_range.h"
19
20 namespace wgt {
21 namespace filesystem {
22
23 namespace bf = boost::filesystem;
24
25 common_installer::Step::Status StepCreateSymbolicLink::process() {
26   assert(context_->manifest_data.get());
27   boost::system::error_code error;
28   for (application_x* app :
29        GListRange<application_x*>(context_->manifest_data.get()->application)) {
30     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
31     bf::path exec_path =
32         context_->pkg_path.get()
33             / bf::path("bin");
34     common_installer::CreateDir(exec_path);
35
36     exec_path /= bf::path(app->appid);
37
38     bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error);
39     if (error) {
40       LOG(ERROR) << "Failed to set symbolic link "
41         << boost::system::system_error(error).what();
42       return Step::Status::ERROR;
43     }
44   }
45   LOG(DEBUG) << "Successfully parse tizen manifest xml";
46
47   return Status::OK;
48 }
49
50 common_installer::Step::Status StepCreateSymbolicLink::undo() {
51   for (application_x* app :
52        GListRange<application_x*>(context_->manifest_data.get()->application)) {
53     bf::path exec_path = context_->pkg_path.get() / "bin" / app->appid;
54     if (bf::exists(exec_path))
55       bf::remove_all(exec_path);
56   }
57   return Status::OK;
58 }
59
60 }  // namespace filesystem
61 }  // namespace wgt