tizen 2.4 release
[framework/web/wrt-installer.git] / src / jobs / widget_uninstall / task_delete_prelaunching_info.cpp
1 /*
2  * Copyright (c) 2013 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_delete_prelaunching_info.cpp
18  * @author  Taejeong Lee (taejeong.lee@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for uninstaller task for un-registration
21  *          pre-launching webapp
22  */
23
24 #include "task_delete_prelaunching_info.h"
25
26 #include <unistd.h>
27 #include <string>
28 #include <sys/stat.h>
29 #include <fstream>
30
31 #include <dpl/exception.h>
32 #include <dpl/platform.h>
33
34 #include <widget_uninstall/job_widget_uninstall.h>
35 #include <widget_uninstall/uninstaller_context.h>
36 #include <widget_uninstall/widget_uninstall_errors.h>
37 #include <boost/filesystem.hpp>
38
39 namespace bf = boost::filesystem;
40
41 namespace {
42 const char* const PRE_LAUNCHING_LIST_DIR = "/opt/usr/etc/wrt_launchpad_daemon/pre_launching_list";
43 }
44
45 namespace Jobs {
46 namespace WidgetUninstall {
47 using namespace WrtDB;
48
49 TaskDeletePreLaunchingInfo::TaskDeletePreLaunchingInfo(UninstallerContext& context) :
50     DPL::TaskDecl<TaskDeletePreLaunchingInfo>(this),
51     m_context(context),
52     m_flagWasDeleted(false)
53 {
54     AddStep(&TaskDeletePreLaunchingInfo::StartStep);
55     AddStep(&TaskDeletePreLaunchingInfo::StepDeletePreLaunchingInfoFile);
56     AddStep(&TaskDeletePreLaunchingInfo::EndStep);
57
58     AddAbortStep(&TaskDeletePreLaunchingInfo::StepAbortDeletePreLaunchingInfo);
59 }
60
61 void TaskDeletePreLaunchingInfo::StepAbortDeletePreLaunchingInfo()
62 {
63     _D("--------- <StepAbortDeletePreLaunchingInfo> : START ----------");
64
65     if (m_flagWasDeleted)
66     {
67         std::string appId = m_context.tzAppid;
68         std::string filePath = std::string(PRE_LAUNCHING_LIST_DIR) + "/" + appId;
69
70         Try {
71             if (!bf::exists(bf::path(filePath)))
72             {
73                 std::ofstream(filePath);
74             }
75         } Catch (const std::exception& e) {
76             _E("Creating empty file failed : %s", filePath.c_str());
77             _E("Exception cought! %s", e.what());
78         }
79         catch (const bf::filesystem_error& ex){
80             _E("boost::filesystem::error: %s", ex.what());
81         }
82
83         if (chmod(filePath.c_str(), 0744) != 0 )
84         {
85             _E("chmod() failed");
86         }
87     }
88
89     _D("--------- <StepAbortDeletePreLaunchingInfo> : END ----------");
90 }
91
92
93 void TaskDeletePreLaunchingInfo::StartStep()
94 {
95     _D("--------- <TaskDeletePreLaunchingInfo> : START ----------");
96 }
97
98 void TaskDeletePreLaunchingInfo::EndStep()
99 {
100     _D("--------- <TaskDeletePreLaunchingInfo> : END ----------");
101 }
102
103 void TaskDeletePreLaunchingInfo::StepDeletePreLaunchingInfoFile()
104 {
105     std::string appId = m_context.tzAppid;
106     bf::path filePath(std::string(PRE_LAUNCHING_LIST_DIR) + "/" + appId);
107
108     try {
109         if (bf::exists(filePath))
110         {
111             JobWidgetUninstall::SecureRemove(filePath);
112             if(!bf::exists(filePath)){
113                 m_flagWasDeleted = true;
114             }
115             else
116             {
117                 _E("Deleted failed : \"%s\"", filePath.c_str());
118             }
119         }
120         else
121         {
122             _E("NOT exist! : \"%s\"", filePath.c_str());
123         }
124     } catch (const bf::filesystem_error& ex) {
125         _E("boost::filesystem::error: %s", ex.what());
126     }
127 }
128
129 } //namespace WidgetUninstall
130 } //namespace Jobs