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 <dpl/wrt-dao-rw/widget_dao.h>
28 #include <dpl/wrt-dao-ro/widget_config.h>
29 #include <dpl/wrt-dao-ro/vconf_config.h>
30 #include <dpl/assert.h>
31 #include <dpl/utils/wrt_utility.h>
33 #include <pkgmgr/pkgmgr_parser.h>
36 #include <widget_install_to_external.h>
40 namespace WidgetUninstall {
41 using namespace WrtDB;
44 const char * const VCONF_KEY_PREFIX = "file/private/";
47 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
48 DPL::TaskDecl<TaskRemoveFiles>(this),
51 if (!m_context.isExternalWidget) {
52 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
54 AddStep(&TaskRemoveFiles::StepRemoveExternalWidget);
56 //AddStep(&TaskRemoveFiles::StepRemoveDesktop);
57 AddStep(&TaskRemoveFiles::StepRemoveManifest);
58 AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
59 AddStep(&TaskRemoveFiles::StepRemoveVconf);
60 AddStep(&TaskRemoveFiles::StepRemoveFinished);
63 TaskRemoveFiles::~TaskRemoveFiles()
66 void TaskRemoveFiles::StepRemoveInstallationDirectory()
68 LogInfo("StepRemoveInstallationDirectory started");
70 m_context.removeStarted = true;
71 std::string widgetDir =
72 m_context.locations->getPackageInstallationDir();
73 if (!WrtUtilRemove(widgetDir)) {
74 LogWarning("Removing widget installation directory failed");
76 std::string dataDir = m_context.locations->getUserDataRootDir();
77 if (!WrtUtilRemove(dataDir)) {
78 LogWarning(dataDir + " is already removed");
80 m_context.job->UpdateProgress(
81 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
82 "Widget INstallation Directory Removal Finished");
85 void TaskRemoveFiles::StepRemoveFinished()
87 LogInfo("StepRemoveFinished finished");
89 m_context.job->UpdateProgress(
90 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
91 "Widget remove steps Finished");
94 void TaskRemoveFiles::StepRemoveDesktop()
96 std::ostringstream desktopFile;
98 desktopFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
99 desktopFile << m_context.tzAppid << ".desktop";
101 unlink(desktopFile.str().c_str());
103 ail_appinfo_h ai = NULL;
106 const char* package = m_context.tzAppid.c_str();
107 LogDebug("ail delete : " << package);
109 ret = ail_get_appinfo(package, &ai);
111 ail_destroy_appinfo(ai);
114 if (AIL_ERROR_OK == ret) {
115 if (0 > ail_desktop_remove(package)) {
116 LogWarning("Failed to remove ail information : " << package);
120 m_context.job->UpdateProgress(
121 UninstallerContext::UNINSTALL_REMOVE_DESKTOP,
122 "Widget remove desktop Finished");
125 void TaskRemoveFiles::StepRemoveManifest()
127 std::ostringstream manifest_name;
128 manifest_name << m_context.tzPkgid << ".xml";
129 std::ostringstream destFile;
130 destFile << "/opt/share/packages" << "/"; //TODO constant with path
131 destFile << manifest_name.str();
132 int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(
133 destFile.str().c_str(), NULL);
134 int ret2 = unlink(destFile.str().c_str());
136 LogWarning("Manifest file failed to parse for uninstallation");
139 LogWarning("No manifest file found: " << destFile.str());
141 LogDebug("Manifest file removed: " << destFile.str());
145 void TaskRemoveFiles::StepRemoveExternalLocations()
147 WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
148 LogDebug("Removing external locations:");
149 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
150 FOREACH(path, externalPaths)
152 if (WrtUtilFileExists(*path)) {
153 LogDebug(" -> " << *path);
154 int ret = remove(path->c_str());
157 "Failed to remove the file: " << path->c_str() <<
158 " with error: " << strerror(errno));
160 } else if (WrtUtilDirExists(*path)) {
161 LogDebug(" -> " << *path);
162 if (!WrtUtilRemove(*path)) {
164 Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
168 LogWarning(" -> " << *path << "(no such a path)");
171 dao.unregisterAllExternalLocations();
174 void TaskRemoveFiles::StepRemoveVconf()
177 WrtDB::VconfConfig::GetVconfKeyRootPath(DPL::FromUTF8String(m_context.
179 if (vconf_unset_recursive(key.c_str())) {
180 LogError("Fail to unset vconf file");
182 LogDebug("vconf file is removed");
186 void TaskRemoveFiles::StepRemoveExternalWidget()
189 WidgetInstallToExtSingleton::Instance().initialize(m_context.tzPkgid);
190 WidgetInstallToExtSingleton::Instance().uninstallation();
191 WidgetInstallToExtSingleton::Instance().deinitialize();
193 Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
196 Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
200 } //namespace WidgetUninstall