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_files.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
20 * @brief Implementation file for uninstaller task for removing widget files
24 #include <widget_uninstall/task_remove_files.h>
25 #include <widget_uninstall/job_widget_uninstall.h>
26 #include <widget_uninstall/uninstaller_context.h>
27 #include <widget_uninstall/widget_uninstall_errors.h>
28 #include <dpl/wrt-dao-rw/widget_dao.h>
29 #include <dpl/wrt-dao-ro/widget_config.h>
30 #include <dpl/assert.h>
31 #include <dpl/exception.h>
32 #include <dpl/utils/wrt_utility.h>
33 #include <dpl/utils/path.h>
35 #include <pkgmgr/pkgmgr_parser.h>
38 #include <widget_install_to_external.h>
39 #include <installer_log.h>
42 namespace WidgetUninstall {
43 using namespace WrtDB;
45 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
46 DPL::TaskDecl<TaskRemoveFiles>(this),
49 AddStep(&TaskRemoveFiles::StartStep);
50 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
51 AddStep(&TaskRemoveFiles::StepRemoveFinished);
52 AddStep(&TaskRemoveFiles::EndStep);
55 TaskRemoveFiles::~TaskRemoveFiles()
58 void TaskRemoveFiles::StepRemoveInstallationDirectory()
60 _D("StepRemoveInstallationDirectory started");
62 int ret = app2ext_get_app_location(m_context.tzPkgid.c_str());
64 if (APP2EXT_SD_CARD == ret) {
65 _D("Remove external directory");
67 WidgetInstallToExtSingleton::Instance().initialize(m_context.tzPkgid);
68 WidgetInstallToExtSingleton::Instance().uninstallation();
69 WidgetInstallToExtSingleton::Instance().deinitialize();
71 Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
73 // Continue uninstall even fail to remove external directory.
74 // i.e.) SD card isn't inserted or unmounted.
75 // This behavior is recommended by platform(app2sd maintainer).
76 _E("Fail to remove external directory");
79 if (APP2EXT_NOT_INSTALLED != ret) {
80 _D("Removing directory");
81 m_context.removeStarted = true;
82 DPL::Utils::Path widgetDir= m_context.installedPath;
84 DPL::Utils::Remove(widgetDir);
85 } Catch(DPL::Utils::Path::BaseException){
86 _E("Removing widget installation directory failed : %s", widgetDir.Fullpath().c_str());
88 DPL::Utils::Path dataDir(m_context.locations->getUserDataRootDir());
90 DPL::Utils::Remove(dataDir);
91 } Catch(DPL::Utils::Path::BaseException){
92 _W("%s is already removed", dataDir.Fullpath().c_str());
95 _E("app is not installed");
96 ThrowMsg(Exceptions::WidgetNotExist, "failed to get app location");
98 } Catch(Exception::RemoveFilesFailed) {
99 ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove directory");
101 m_context.job->UpdateProgress(
102 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
103 "Widget INstallation Directory Removal Finished");
106 void TaskRemoveFiles::StepRemoveFinished()
108 _D("StepRemoveFinished finished");
110 m_context.job->UpdateProgress(
111 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
112 "Widget remove steps Finished");
115 void TaskRemoveFiles::StartStep()
117 LOGD("--------- <TaskRemoveFiles> : START ----------");
120 void TaskRemoveFiles::EndStep()
122 LOGD("--------- <TaskRemoveFiles> : END ----------");
124 } //namespace WidgetUninstall