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/wrt-dao-ro/vconf_config.h>
31 #include <dpl/assert.h>
32 #include <dpl/exception.h>
33 #include <dpl/utils/wrt_utility.h>
35 #include <pkgmgr/pkgmgr_parser.h>
38 #include <widget_install_to_external.h>
42 namespace WidgetUninstall {
43 using namespace WrtDB;
46 const char * const VCONF_KEY_PREFIX = "file/private/";
49 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
50 DPL::TaskDecl<TaskRemoveFiles>(this),
53 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
54 AddStep(&TaskRemoveFiles::StepRemoveManifest);
55 AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
56 AddStep(&TaskRemoveFiles::StepRemoveVconf);
57 AddStep(&TaskRemoveFiles::StepRemoveFinished);
60 TaskRemoveFiles::~TaskRemoveFiles()
63 void TaskRemoveFiles::StepRemoveInstallationDirectory()
65 LogInfo("StepRemoveInstallationDirectory started");
67 if (APP2EXT_SD_CARD !=
68 app2ext_get_app_location(m_context.tzPkgid.c_str()))
70 LogDebug("Removing directory");
71 m_context.removeStarted = true;
72 std::string widgetDir =
73 m_context.locations->getPackageInstallationDir();
74 if (!WrtUtilRemove(widgetDir)) {
75 LogError("Removing widget installation directory failed");
77 std::string dataDir = m_context.locations->getUserDataRootDir();
78 if (!WrtUtilRemove(dataDir)) {
79 LogWarning(dataDir + " is already removed");
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 } Catch(Exception::RemoveFilesFailed) {
95 ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove directory");
98 m_context.job->UpdateProgress(
99 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
100 "Widget INstallation Directory Removal Finished");
103 void TaskRemoveFiles::StepRemoveFinished()
105 LogInfo("StepRemoveFinished finished");
107 m_context.job->UpdateProgress(
108 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
109 "Widget remove steps Finished");
112 void TaskRemoveFiles::StepRemoveManifest()
114 std::ostringstream manifest_name;
115 manifest_name << m_context.tzPkgid << ".xml";
116 std::ostringstream destFile;
117 destFile << "/opt/share/packages" << "/"; //TODO constant with path
118 destFile << manifest_name.str();
119 int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(
120 destFile.str().c_str(), NULL);
121 int ret2 = unlink(destFile.str().c_str());
123 LogWarning("Manifest file failed to parse for uninstallation");
126 LogWarning("No manifest file found: " << destFile.str());
128 LogDebug("Manifest file removed: " << destFile.str());
132 void TaskRemoveFiles::StepRemoveExternalLocations()
134 if (!m_context.removeAbnormal) {
135 WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
136 LogDebug("Removing external locations:");
137 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
138 FOREACH(path, externalPaths)
140 if (WrtUtilFileExists(*path)) {
141 LogDebug(" -> " << *path);
142 int ret = remove(path->c_str());
145 "Failed to remove the file: " << path->c_str() <<
146 " with error: " << strerror(errno));
148 } else if (WrtUtilDirExists(*path)) {
149 LogDebug(" -> " << *path);
150 if (!WrtUtilRemove(*path)) {
152 Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
156 LogWarning(" -> " << *path << "(no such a path)");
159 dao.unregisterAllExternalLocations();
163 void TaskRemoveFiles::StepRemoveVconf()
165 if (!m_context.removeAbnormal) {
167 WrtDB::VconfConfig::GetVconfKeyRootPath(DPL::FromUTF8String(m_context.
169 if (vconf_unset_recursive(key.c_str())) {
170 LogError("Fail to unset vconf file");
172 LogDebug("vconf file is removed");
176 } //namespace WidgetUninstall