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_new_db_insert.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
19 * @author Soyoung kim(sy037.kim@samsung.com)
21 * @brief Implementation file for installer task database updating for widget update
25 #include <widget_install/task_database.h>
26 #include <widget_install/job_widget_install.h>
27 #include <widget_install/widget_install_errors.h>
28 #include <widget_install/widget_install_context.h>
29 //#include <dpl/wrt-dao-ro/config_parser_data.h>
30 #include <dpl/wrt-dao-rw/widget_dao.h>
31 #include <dpl/foreach.h>
32 #include <dpl/utils/wrt_utility.h>
33 #include <dpl/log/log.h>
34 #include <dpl/assert.h>
35 //#include <dpl/wrt-dao-ro/global_config.h>
39 using namespace WrtDB;
42 namespace WidgetInstall {
43 TaskDatabase::TaskDatabase(InstallerContext& context) :
44 DPL::TaskDecl<TaskDatabase>(this),
47 AddStep(&TaskDatabase::StepRegisterExternalFiles);
48 AddStep(&TaskDatabase::StepDBInsert);
50 AddAbortStep(&TaskDatabase::StepAbortDBInsert);
53 void TaskDatabase::StepDBInsert()
57 /* Set install Time */
58 time(&m_context.widgetConfig.installedTime);
60 if (m_context.existingWidgetInfo.isExist) //update
62 LogInfo("Registering widget... (update)");
63 WidgetDAO::registerOrUpdateWidget(
64 m_context.locations->getPkgname(),
65 m_context.widgetConfig,
66 m_context.wacSecurity);
68 else //new installation
70 LogInfo("Registering widget...");
71 WidgetDAO::registerWidget(
72 m_context.locations->getPkgname(),
73 m_context.widgetConfig,
74 m_context.wacSecurity);
77 FOREACH (cap, m_context.staticPermittedDevCaps) {
78 LogInfo("staticPermittedDevCaps : " << cap->first
79 << " smack status: " << cap->second);
82 LogInfo("Widget registered");
84 Catch(WidgetDAO::Exception::DatabaseError)
86 LogError("Database failure!");
87 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
89 Catch(DPL::DB::SqlConnection::Exception::Base)
91 LogError("Database failure!");
92 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
95 m_context.job->UpdateProgress(
96 InstallerContext::INSTALL_NEW_DB_INSERT,
97 "New Widget DB UPDATE Finished");
100 void TaskDatabase::StepRegisterExternalFiles()
102 WrtDB::ExternalLocationList externalLocationsUpdate = m_context.locations->listExternalLocations();
103 if (m_context.existingWidgetInfo.isExist) //update
105 WidgetDAO dao(m_context.locations->getPkgname());
106 WrtDB::ExternalLocationList externalLocationsDB = dao.getWidgetExternalLocations();
107 LogDebug("Removing external files:");
108 FOREACH(file, externalLocationsDB)
110 if(std::find(externalLocationsUpdate.begin(), externalLocationsUpdate.end(), *file) == externalLocationsUpdate.end())
112 if(WrtUtilFileExists(*file))
114 LogDebug(" -> " << *file);
115 remove(file->c_str());
117 else if(WrtUtilDirExists(*file))
119 LogDebug(" -> " << *file);
120 if(!WrtUtilRemove(*file)){
121 ThrowMsg(Exceptions::RemovingFolderFailure,
122 "Failed to remove external directory");
127 LogWarning(" -> " << *file << "(no such a path)");
132 LogDebug("Registering external files:");
133 FOREACH(file, externalLocationsUpdate)
135 LogDebug(" -> " << *file);
138 //set external lcoations to be registered
139 m_context.widgetConfig.externalLocations = externalLocationsUpdate;
142 void TaskDatabase::StepAbortDBInsert()
144 LogWarning("[DB Update Task] Aborting... (DB Clean)");
147 WidgetDAO::unregisterWidget(m_context.locations->getPkgname());
149 LogDebug("Cleaning DB successful!");
151 Catch(DPL::DB::SqlConnection::Exception::Base)
153 LogError("Failed to handle StepAbortDBClean!");
157 } //namespace WidgetInstall