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_recovery.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
20 * @brief Implementation file for installer task recovery
22 #include "task_recovery.h"
24 #include <dpl/log/log.h>
25 #include <dpl/errno_string.h>
26 #include <dpl/foreach.h>
28 #include <dpl/wrt-dao-ro/widget_config.h>
29 #include <dpl/wrt-dao-ro/global_config.h>
30 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
31 #include <dpl/wrt-dao-rw/widget_dao.h>
32 #include <dpl/utils/wrt_utility.h>
33 #include <dpl/utils/path.h>
34 #include <ace_api_install.h>
35 #include <ace_registration.h>
36 #include <ace-common/ace_api_common.h>
38 #include <widget_install/job_widget_install.h>
39 #include <widget_install/widget_install_context.h>
40 #include <widget_install/widget_install_errors.h>
41 #include <installer_log.h>
43 using namespace WrtDB;
46 const std::string BACKUP_ID = ".backup";
50 namespace WidgetInstall {
51 TaskRecovery::TaskRecovery(InstallerContext& context) :
52 DPL::TaskDecl<TaskRecovery>(this),
55 AddStep(&TaskRecovery::StartStep);
56 AddStep(&TaskRecovery::StepRecoveryDirectory);
57 AddStep(&TaskRecovery::StepRecoveryDatabase);
58 AddStep(&TaskRecovery::EndStep);
61 void TaskRecovery::StepRecoveryDirectory()
63 _D("StepRecoveryDirectory ...");
64 // check backup folder
65 DPL::Utils::Path installedPath(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
66 installedPath /= m_context.widgetConfig.tzPkgid;
68 DPL::Utils::Path backupPath(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
69 backupPath /= DPL::ToUTF8String(m_context.widgetConfig.tzPkgid) + BACKUP_ID;
71 _D("installedPath : %s", installedPath.Fullpath().c_str());
72 _D("backupPath : %s", backupPath.Fullpath().c_str());
74 if (backupPath.Exists()) {
75 DPL::Utils::TryRemove(installedPath);
77 DPL::Utils::Rename(backupPath, installedPath);
79 ThrowMsg(Exceptions::RecoveryFailed, "backup folder doesn't exist");
83 void TaskRecovery::StepRecoveryDatabase()
85 _D("StepRecoveryDatabase ... %s", m_context.widgetConfig.tzPkgid.c_str());
87 std::string backupId, deleteId;
89 TizenAppId dbAppId = WidgetDAOReadOnly::getTizenAppId(m_context.widgetConfig.tzPkgid);
90 _D("Get appid : %ls", dbAppId.c_str());
91 std::string appId = DPL::ToUTF8String(dbAppId);
93 if (0 == appId.compare(appId.size() - BACKUP_ID.length(), BACKUP_ID.length(), BACKUP_ID)) {
95 deleteId = backupId.substr(0, backupId.length() -
98 backupId = appId + BACKUP_ID;
102 if (WrtDB::WidgetDAOReadOnly::isWidgetInstalled(DPL::FromUTF8String(backupId))) {
103 _D("Recovery Database...");
104 _D("backupId %s " , backupId.c_str());
105 _D("deleteId %s " , deleteId.c_str());
108 ace_unregister_widget(static_cast<ace_widget_handle_t>(
109 WidgetDAOReadOnly::getHandle(DPL::
110 FromUTF8String(deleteId))));
111 ace_unregister_widget(static_cast<ace_widget_handle_t>(
112 WidgetDAOReadOnly::getHandle(DPL::
113 FromUTF8String(backupId))));
115 WidgetDAO::unregisterWidget(DPL::FromUTF8String(deleteId));
116 WidgetDAO::updateTizenAppId(DPL::FromUTF8String(backupId),
117 DPL::FromUTF8String(deleteId));
119 if(!AceApi::registerAceWidgetFromDB(WidgetDAOReadOnly::getHandle(
120 DPL::FromUTF8String(deleteId)))) {
121 _E("ace database restore failed");
125 WidgetDAOReadOnly dao(DPL::FromUTF8String(deleteId));
126 m_context.requestedPath =
127 DPL::ToUTF8String(*dao.getWidgetInstalledPath());
129 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
131 ThrowMsg(Exceptions::RecoveryFailed, "[WidgetNotExist] Failure in recovery db");
133 Catch(WidgetDAO::Exception::DatabaseError)
135 ThrowMsg(Exceptions::RecoveryFailed, "[DatabaseError] Failure in recovery db");
139 void TaskRecovery::StartStep()
141 LOGD("--------- <TaskRecovery> : START ----------");
144 void TaskRecovery::EndStep()
146 LOGD("--------- <TaskRecovery> : END ----------");
148 } //namespace RecoveryInstall