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
23 #include <widget_uninstall/task_remove_files.h>
24 #include <widget_uninstall/job_widget_uninstall.h>
25 #include <widget_uninstall/uninstaller_context.h>
26 #include <dpl/wrt-dao-rw/widget_dao.h>
27 #include <dpl/wrt-dao-ro/widget_config.h>
28 #include <dpl/assert.h>
29 #include <dpl/utils/wrt_utility.h>
31 #include <pkgmgr/pkgmgr_parser.h>
34 namespace WidgetUninstall {
36 using namespace WrtDB;
38 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
39 DPL::TaskDecl<TaskRemoveFiles>(this),
42 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
43 //AddStep(&TaskRemoveFiles::StepRemoveDesktop);
44 AddStep(&TaskRemoveFiles::StepRemoveManifest);
45 AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
46 AddStep(&TaskRemoveFiles::StepRemoveFinished);
49 TaskRemoveFiles::~TaskRemoveFiles()
53 void TaskRemoveFiles::StepRemoveInstallationDirectory()
55 LogInfo("StepRemoveInstallationDirectory started");
57 m_context.removeStarted = true;
58 std::string widgetDir =
59 m_context.locations->getPackageInstallationDir();
60 if(!WrtUtilRemove(widgetDir)){
61 LogWarning("Removing widget installation directory failed");
63 m_context.job->UpdateProgress(
64 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
65 "Widget INstallation Directory Removal Finished");
68 void TaskRemoveFiles::StepRemoveFinished()
70 LogInfo("StepRemoveFinished finished");
72 m_context.job->UpdateProgress(
73 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
74 "Widget remove steps Finished");
77 void TaskRemoveFiles::StepRemoveDesktop()
79 std::ostringstream desktopFile;
81 desktopFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
82 desktopFile << m_context.pkgname << ".desktop";
84 unlink(desktopFile.str().c_str());
86 ail_appinfo_h ai = NULL;
89 const char* package = m_context.pkgname.c_str();
90 LogDebug("ail delete : " << package);
92 ret = ail_package_get_appinfo(package, &ai);
94 ail_package_destroy_appinfo(ai);
97 if (AIL_ERROR_OK == ret) {
98 if ( 0 > ail_desktop_remove(package)) {
99 LogWarning("Failed to remove ail information : " << package);
103 m_context.job->UpdateProgress(
104 UninstallerContext::UNINSTALL_REMOVE_DESKTOP,
105 "Widget remove desktop Finished");
108 void TaskRemoveFiles::StepRemoveManifest()
110 std::ostringstream manifest_name;
111 manifest_name << m_context.pkgname << ".xml";
112 std::ostringstream destFile;
113 destFile << "/opt/share/packages" << "/"; //TODO constant with path
114 destFile << manifest_name.str();
115 int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(destFile.str().c_str(), NULL);
116 int ret2 = unlink(destFile.str().c_str());
119 LogWarning("Manifest file failed to parse for uninstallation");
123 LogWarning("No manifest file found: " << destFile.str());
127 LogDebug("Manifest file removed: " << destFile.str());
131 void TaskRemoveFiles::StepRemoveExternalLocations()
133 WidgetDAO dao(m_context.widgetHandle);
134 LogDebug("Removing external locations:");
135 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
136 FOREACH(path, externalPaths)
138 if(WrtUtilFileExists(*path))
140 LogDebug(" -> " << *path);
141 remove(path->c_str());
143 else if(WrtUtilDirExists(*path))
145 LogDebug(" -> " << *path);
146 if(!WrtUtilRemove(*path)){
147 Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::RemoveFilesFailed);
152 LogWarning(" -> " << *path << "(no such a path)");
155 dao.unregisterAllExternalLocations();
158 } //namespace WidgetUninstall