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 std::string dataDir = m_context.locations->getBasePrivateDir();
66 if(!WrtUtilRemove(dataDir)){
67 LogWarning(dataDir + " is already removed");
69 m_context.job->UpdateProgress(
70 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
71 "Widget INstallation Directory Removal Finished");
74 void TaskRemoveFiles::StepRemoveFinished()
76 LogInfo("StepRemoveFinished finished");
78 m_context.job->UpdateProgress(
79 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
80 "Widget remove steps Finished");
83 void TaskRemoveFiles::StepRemoveDesktop()
85 std::ostringstream desktopFile;
87 desktopFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
88 desktopFile << m_context.pkgname << ".desktop";
90 unlink(desktopFile.str().c_str());
92 ail_appinfo_h ai = NULL;
95 const char* package = m_context.pkgname.c_str();
96 LogDebug("ail delete : " << package);
98 ret = ail_package_get_appinfo(package, &ai);
100 ail_package_destroy_appinfo(ai);
103 if (AIL_ERROR_OK == ret) {
104 if ( 0 > ail_desktop_remove(package)) {
105 LogWarning("Failed to remove ail information : " << package);
109 m_context.job->UpdateProgress(
110 UninstallerContext::UNINSTALL_REMOVE_DESKTOP,
111 "Widget remove desktop Finished");
114 void TaskRemoveFiles::StepRemoveManifest()
116 std::ostringstream manifest_name;
117 manifest_name << m_context.pkgname << ".xml";
118 std::ostringstream destFile;
119 destFile << "/opt/share/packages" << "/"; //TODO constant with path
120 destFile << manifest_name.str();
121 int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(destFile.str().c_str(), NULL);
122 int ret2 = unlink(destFile.str().c_str());
125 LogWarning("Manifest file failed to parse for uninstallation");
129 LogWarning("No manifest file found: " << destFile.str());
133 LogDebug("Manifest file removed: " << destFile.str());
137 void TaskRemoveFiles::StepRemoveExternalLocations()
139 WidgetDAO dao(m_context.locations->getPkgname());
140 LogDebug("Removing external locations:");
141 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
142 FOREACH(path, externalPaths)
144 if(WrtUtilFileExists(*path))
146 LogDebug(" -> " << *path);
147 int ret = remove(path->c_str());
149 LogError("Failed to remove the file: " << path->c_str() << " with error: " << strerror(errno));
152 else if(WrtUtilDirExists(*path))
154 LogDebug(" -> " << *path);
155 if(!WrtUtilRemove(*path)){
156 Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::RemoveFilesFailed);
161 LogWarning(" -> " << *path << "(no such a path)");
164 dao.unregisterAllExternalLocations();
167 } //namespace WidgetUninstall