2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file task_db_update.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
20 * @brief Implementation file for uninstaller task database updating
23 #include <dpl/platform.h>
24 #include <widget_uninstall/task_db_update.h>
25 #include <widget_uninstall/job_widget_uninstall.h>
26 #include <widget_uninstall/widget_uninstall_errors.h>
28 #include <web_provider_widget_info.h>
30 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
31 #include <dpl/assert.h>
32 #include <dpl/wrt-dao-rw/widget_dao.h>
33 #include <boost/filesystem.hpp>
34 #include <dpl/log/secure_log.h>
36 using namespace WrtDB;
37 namespace bf = boost::filesystem;
40 namespace WidgetUninstall {
41 TaskDbUpdate::TaskDbUpdate(UninstallerContext& context) :
42 DPL::TaskDecl<TaskDbUpdate>(this),
45 AddStep(&TaskDbUpdate::StartStep);
46 AddStep(&TaskDbUpdate::StepRemoveExternalLocations);
47 AddStep(&TaskDbUpdate::StepDbUpdate);
49 AddStep(&TaskDbUpdate::StepLiveboxDBDelete);
51 AddStep(&TaskDbUpdate::EndStep);
54 TaskDbUpdate::~TaskDbUpdate()
57 void TaskDbUpdate::StepDbUpdate()
61 //TODO: widget handle should not be used any more
62 FOREACH(it , m_context.tzAppIdList){
63 WidgetDAO::unregisterWidget(*it);
65 _D("Unregistered widget successfully!");
67 Catch(DPL::DB::SqlConnection::Exception::Base)
69 _E("Failed to handle StepDbUpdate!");
70 ReThrowMsg(Exceptions::DatabaseFailure,
71 "Failed to handle StepDbUpdate!");
76 void TaskDbUpdate::StepLiveboxDBDelete()
78 FOREACH(it, m_context.tzAppIdList){
80 web_provider_widget_delete_by_app_id(DPL::ToUTF8String(*it).c_str());
83 _D("failed to delete box info");
85 _D("delete box info: %s", it);
91 void TaskDbUpdate::StepRemoveExternalLocations()
93 if (!m_context.removeAbnormal) {
94 FOREACH(it, m_context.tzAppIdList){
96 _D("Removing external locations:");
97 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
98 FOREACH(file, externalPaths)
100 bf::path path(*file);
102 if(bf::exists(path)){
103 JobWidgetUninstall::SecureRemove(path);
105 _W(" -> %s(no such a path)", path.c_str());
107 } catch (const bf::filesystem_error& ex) {
108 _E("Failed to remove the file: %s", path.c_str());
109 Throw(Jobs::WidgetUninstall::TaskDbUpdate::Exception::RemoveFilesFailed);
112 dao.unregisterAllExternalLocations();
117 void TaskDbUpdate::StartStep()
119 LOGI("--------- <TaskDbUpdate> : START ----------");
122 void TaskDbUpdate::EndStep()
124 m_context.job->UpdateProgress(
125 UninstallerContext::UNINSTALL_DB_UPDATE,
126 "Widget DB Update Finished");
128 LOGI("--------- <TaskDbUpdate> : END ----------");
130 } //namespace WidgetUninstall