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>
36 namespace WidgetUninstall {
38 using namespace WrtDB;
40 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
41 DPL::TaskDecl<TaskRemoveFiles>(this),
44 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
45 //AddStep(&TaskRemoveFiles::StepRemoveDesktop);
46 AddStep(&TaskRemoveFiles::StepRemoveManifest);
47 AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
48 AddStep(&TaskRemoveFiles::StepRemoveFinished);
51 TaskRemoveFiles::~TaskRemoveFiles()
55 void TaskRemoveFiles::StepRemoveInstallationDirectory()
57 LogInfo("StepRemoveInstallationDirectory started");
59 m_context.removeStarted = true;
60 std::string widgetDir =
61 m_context.locations->getPackageInstallationDir();
62 if(!WrtUtilRemove(widgetDir)){
63 LogWarning("Removing widget installation directory failed");
65 m_context.job->UpdateProgress(
66 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
67 "Widget INstallation Directory Removal Finished");
70 void TaskRemoveFiles::StepRemoveFinished()
72 LogInfo("StepRemoveFinished finished");
74 m_context.job->UpdateProgress(
75 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
76 "Widget remove steps Finished");
79 void TaskRemoveFiles::StepRemoveDesktop()
81 std::ostringstream desktopFile;
83 desktopFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
84 desktopFile << m_context.pkgname << ".desktop";
86 unlink(desktopFile.str().c_str());
88 ail_appinfo_h ai = NULL;
91 const char* package = m_context.pkgname.c_str();
92 LogDebug("ail delete : " << package);
94 ret = ail_package_get_appinfo(package, &ai);
96 ail_package_destroy_appinfo(ai);
99 if (AIL_ERROR_OK == ret) {
100 if ( 0 > ail_desktop_remove(package)) {
101 LogWarning("Failed to remove ail information : " << package);
105 m_context.job->UpdateProgress(
106 UninstallerContext::UNINSTALL_REMOVE_DESKTOP,
107 "Widget remove desktop Finished");
110 void TaskRemoveFiles::StepRemoveManifest()
112 std::ostringstream manifest_name;
113 manifest_name << m_context.pkgname << ".xml";
114 std::ostringstream destFile;
115 destFile << "/opt/share/packages" << "/"; //TODO constant with path
116 destFile << manifest_name.str();
117 int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(destFile.str().c_str(), NULL);
118 int ret2 = unlink(destFile.str().c_str());
121 LogWarning("Manifest file failed to parse for uninstallation");
125 LogWarning("No manifest file found: " << destFile.str());
129 LogDebug("Manifest file removed: " << destFile.str());
133 void TaskRemoveFiles::StepRemoveExternalLocations()
135 WidgetDAO dao(m_context.locations->getPkgname());
136 LogDebug("Removing external locations:");
137 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
138 FOREACH(path, externalPaths)
140 if(WrtUtilFileExists(*path))
142 LogDebug(" -> " << *path);
143 int ret = remove(path->c_str());
145 LogDebug("Failed to remove the file: " << path->c_str() << " with error: " << strerror(errno));
148 else if(WrtUtilDirExists(*path))
150 LogDebug(" -> " << *path);
151 if(!WrtUtilRemove(*path)){
152 Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::RemoveFilesFailed);
157 LogWarning(" -> " << *path << "(no such a path)");
160 dao.unregisterAllExternalLocations();
163 } //namespace WidgetUninstall