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>
41 namespace WidgetUninstall {
42 using namespace WrtDB;
44 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
45 DPL::TaskDecl<TaskRemoveFiles>(this),
48 AddStep(&TaskRemoveFiles::StartStep);
49 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
50 AddStep(&TaskRemoveFiles::StepRemoveManifest);
51 AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
52 AddStep(&TaskRemoveFiles::StepRemoveFinished);
53 AddStep(&TaskRemoveFiles::EndStep);
56 TaskRemoveFiles::~TaskRemoveFiles()
59 void TaskRemoveFiles::StepRemoveInstallationDirectory()
61 LogDebug("StepRemoveInstallationDirectory started");
63 int ret = app2ext_get_app_location(m_context.tzPkgid.c_str());
65 if (APP2EXT_INTERNAL_MEM == ret) {
66 LogDebug("Removing directory");
67 m_context.removeStarted = true;
68 DPL::Utils::Path widgetDir= m_context.installedPath;
70 DPL::Utils::Remove(widgetDir);
71 } Catch(DPL::Utils::Path::BaseException){
72 LogError("Removing widget installation directory failed : " <<
73 widgetDir.Fullpath());
75 DPL::Utils::Path dataDir(m_context.locations->getUserDataRootDir());
77 DPL::Utils::Remove(dataDir);
78 } Catch(DPL::Utils::Path::BaseException){
79 LogWarning(dataDir.Fullpath() << " is already removed");
81 } else if (APP2EXT_SD_CARD == ret) {
82 LogDebug("Removing sdcard directory");
84 WidgetInstallToExtSingleton::Instance().initialize(m_context.tzPkgid);
85 WidgetInstallToExtSingleton::Instance().uninstallation();
86 WidgetInstallToExtSingleton::Instance().deinitialize();
88 Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
90 Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
94 LogError("app is not installed");
95 ThrowMsg(Exceptions::WidgetNotExist, "failed to get app location");
97 } Catch(Exception::RemoveFilesFailed) {
98 ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove directory");
100 m_context.job->UpdateProgress(
101 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
102 "Widget INstallation Directory Removal Finished");
105 void TaskRemoveFiles::StepRemoveFinished()
107 LogDebug("StepRemoveFinished finished");
109 m_context.job->UpdateProgress(
110 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
111 "Widget remove steps Finished");
114 void TaskRemoveFiles::StepRemoveManifest()
116 std::ostringstream manifest_name;
117 manifest_name << m_context.tzPkgid << ".xml";
118 DPL::Utils::Path destFile;
119 const DPL::Utils::Path PRELOAD_INSTALLED_PATH("/usr/apps");
120 const DPL::Utils::Path USR_PACKAGES_PATH("/usr/share/packages");
121 const DPL::Utils::Path OPT_PACKAGES_PATH("/opt/share/packages");
122 if (0 == (m_context.installedPath.Fullpath()).compare(0,
123 PRELOAD_INSTALLED_PATH.Fullpath().length(),
124 PRELOAD_INSTALLED_PATH.Fullpath())) {
125 LogDebug("This widget is preloaded.");
126 destFile = USR_PACKAGES_PATH;
128 destFile = OPT_PACKAGES_PATH;
130 destFile /= manifest_name.str();
131 DPL::Utils::Path pre_manifest = USR_PACKAGES_PATH;
132 pre_manifest /= manifest_name.str();
134 if (!(destFile.Exists() == 0 && pre_manifest.Exists())) {
135 int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(
136 destFile.Fullpath().c_str(), NULL);
138 LogWarning("Manifest file failed to parse for uninstallation");
141 if (!DPL::Utils::TryRemove(destFile)) {
142 LogWarning("No manifest file found: " << destFile.Fullpath());
144 LogDebug("Manifest file removed: " << destFile.Fullpath());
148 void TaskRemoveFiles::StepRemoveExternalLocations()
150 if (!m_context.removeAbnormal) {
151 WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
152 LogDebug("Removing external locations:");
153 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
154 FOREACH(file, externalPaths)
156 DPL::Utils::Path path(*file);
159 LogDebug(" -> " << path.Fullpath());
161 DPL::Utils::Remove(path);
162 }Catch(DPL::Utils::Path::BaseException){
163 LogError("Failed to remove the file: " << path.Fullpath());
165 } else if (path.IsDir()){
166 LogDebug(" -> " << path.Fullpath());
168 DPL::Utils::Remove(path);
169 }Catch(DPL::Utils::Path::BaseException){
170 Throw(Jobs::WidgetUninstall::TaskRemoveFiles::
171 Exception::RemoveFilesFailed);
175 LogWarning(" -> " << path.Fullpath() << "(no such a path)");
178 dao.unregisterAllExternalLocations();
182 void TaskRemoveFiles::StartStep()
184 LogDebug("--------- <TaskRemoveFiles> : START ----------");
187 void TaskRemoveFiles::EndStep()
189 LogDebug("--------- <TaskRemoveFiles> : END ----------");
191 } //namespace WidgetUninstall