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_remove_backup.cpp
18 * @author Soyoung kim(sy037.kim@samsung.com)
20 * @brief Implementation file for installer task backup files remove
22 #include <widget_install/task_remove_backup.h>
27 #include <dpl/wrt-dao-ro/global_config.h>
28 #include <dpl/foreach.h>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
31 #include <dpl/utils/wrt_utility.h>
32 #include <dpl/wrt-dao-rw/widget_dao.h>
33 #include <widget_install/job_widget_install.h>
34 #include <widget_install/widget_install_errors.h>
35 #include <widget_install/widget_install_context.h>
37 using namespace WrtDB;
40 namespace WidgetInstall {
41 TaskRemoveBackupFiles::TaskRemoveBackupFiles(InstallerContext& context) :
42 DPL::TaskDecl<TaskRemoveBackupFiles>(this),
45 AddStep(&TaskRemoveBackupFiles::StartStep);
46 if (m_context.mode.extension != InstallMode::ExtensionType::DIR)
48 AddStep(&TaskRemoveBackupFiles::StepRemoveBackupFiles);
50 AddStep(&TaskRemoveBackupFiles::StepDeleteBackupDB);
51 AddStep(&TaskRemoveBackupFiles::EndStep);
54 void TaskRemoveBackupFiles::StepRemoveBackupFiles()
56 std::ostringstream backupDir;
57 backupDir << m_context.locations->getBackupDir();
59 if (WrtUtilRemove(backupDir.str())) {
60 LogDebug("Success to remove backup files : " << backupDir.str());
62 LogError("Failed to remove backup directory : " << backupDir.str());
63 ThrowMsg(Exceptions::RemoveBackupFailed,
64 "Error occurs during removing existing folder");
67 std::string tmp = m_context.locations->getTemporaryPackageDir();
68 if (WrtUtilRemove(tmp)) {
69 LogDebug("Success to remove temp directory : " << tmp);
71 LogError("Failed to remove temp directory : " << tmp);
75 void TaskRemoveBackupFiles::StepDeleteBackupDB()
77 LogDebug("StepDeleteBackupDB");
78 std::string oldAppid =
79 DPL::ToUTF8String(m_context.widgetConfig.tzAppid) + ".backup";
83 WidgetDAO::unregisterWidget(DPL::FromUTF8String(oldAppid));
85 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
87 LogError("Fail to delete old version db information");
91 void TaskRemoveBackupFiles::StartStep()
93 LogDebug("--------- <TaskRemoveBackupFiles> : START ----------");
96 void TaskRemoveBackupFiles::EndStep()
98 LogDebug("--------- <TaskRemoveBackupFiles> : END ----------");
100 } //namespace WidgetInstall