Rename invalid WRT_SMACK_LABEL macro to WRT_SMACK_ENABLED
[platform/framework/web/wrt-installer.git] / src / jobs / widget_install / task_recovery.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    task_recovery.cpp
18  * @author  Soyoung Kim (sy037.kim@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task recovery
21  */
22 #include "task_recovery.h"
23
24 #include <pwd.h>
25 #include <grp.h>
26 #include <unistd.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <string>
30 #include <ail.h>
31
32 #include <dpl/errno_string.h>
33 #include <dpl/foreach.h>
34
35 #include <dpl/wrt-dao-ro/widget_config.h>
36 #include <dpl/utils/wrt_utility.h>
37 #include <widget_install/job_widget_install.h>
38 #include <widget_install/widget_install_context.h>
39 #include <widget_install/widget_install_errors.h>
40
41 #include <installer_log.h>
42
43 using namespace WrtDB;
44
45 namespace Jobs {
46 namespace WidgetInstall {
47 TaskRecovery::TaskRecovery(InstallerContext& context) :
48     DPL::TaskDecl<TaskRecovery>(this),
49     m_context(context)
50 {
51     AddStep(&TaskRecovery::StartStep);
52     AddStep(&TaskRecovery::StepCreateCheckFile);
53     AddStep(&TaskRecovery::EndStep);
54 }
55
56 void TaskRecovery::StartStep()
57 {
58     _D("---------- <TaskRecovery> : START ----------");
59 }
60
61 void TaskRecovery::EndStep()
62 {
63     m_context.job->UpdateProgress(
64         InstallerContext::INSTALL_CHECK_FILE,
65         "Create information file for recovery");
66
67     _D("---------- <TaskRecovery> : END ----------");
68 }
69
70 void TaskRecovery::StepCreateCheckFile()
71 {
72     _D("Step: create information file for recovery");
73
74     size_t pos = m_context.locations->getWidgetSource().rfind("/");
75     std::ostringstream infoPath;
76     infoPath << GlobalConfig::GetTempInstallInfoPath();
77     infoPath << "/";
78     infoPath << m_context.locations->getWidgetSource().substr(pos + 1);
79
80     FILE *temp = fopen(infoPath.str().c_str(), "w+");
81     if (temp != NULL) {
82         fputs(m_context.locations->getWidgetSource().c_str(), temp);
83         int ret = fsync(temp->_fileno);
84         fclose(temp);
85         if (-1 == ret) {
86             ThrowMsg(Exceptions::FileOperationFailed, "Fail to fsync for recovery.");
87         }
88
89         m_context.installInfo = infoPath.str();
90
91         _D("Create file : %s", m_context.installInfo.c_str());
92     } else {
93         ThrowMsg(Exceptions::FileOperationFailed, "Fail to create file for recovery.");
94     }
95 }
96 } //namespace WidgetInstall
97 } //namespace Jobs