Add OOM exception handler
[platform/core/appfw/wgt-backend.git] / src / wgt / step / filesystem / step_wgt_resource_directory.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "wgt/step/filesystem/step_wgt_resource_directory.h"
6
7 #include <boost/filesystem/path.hpp>
8
9 #include <common/utils/file_util.h>
10
11 namespace bf = boost::filesystem;
12 namespace bs = boost::system;
13
14 namespace wgt {
15 namespace filesystem {
16
17 common_installer::Step::Status StepWgtResourceDirectory::process() {
18   bf::path temp_path = context_->unpacked_dir_path.get();
19   temp_path += ".temp";
20   bf::path resource_path = context_->unpacked_dir_path.get() / "res/wgt";
21
22   if (!common_installer::MoveDir(context_->unpacked_dir_path.get(),
23                                         temp_path)) {
24     LOG(ERROR) << "Failed to move: " << context_->unpacked_dir_path.get()
25                << " to: " << temp_path;
26     return Status::APP_DIR_ERROR;
27   }
28   bs::error_code error;
29   bf::create_directories(resource_path.parent_path(), error);
30   if (error) {
31     LOG(ERROR) << "Failed to create proper directory structure in widget";
32     return Status::APP_DIR_ERROR;
33   }
34   if (!common_installer::MoveDir(temp_path, resource_path)) {
35     LOG(ERROR) << "Failed to move: " << temp_path << " to: " << resource_path;
36     return Status::APP_DIR_ERROR;
37   }
38
39   LOG(INFO) << "Widget content moved to res/wgt subdirectory";
40   return Status::OK;
41 }
42
43 }  // namespace filesystem
44 }  // namespace wgt