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/assert.h>
31 #include <dpl/exception.h>
32 #include <pkgmgr/pkgmgr_parser.h>
35 #include <widget_install_to_external.h>
36 #include <boost/filesystem.hpp>
37 #include <dpl/log/secure_log.h>
39 namespace bf = boost::filesystem;
42 namespace WidgetUninstall {
43 using namespace WrtDB;
45 TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
46 DPL::TaskDecl<TaskRemoveFiles>(this),
49 AddStep(&TaskRemoveFiles::StartStep);
50 AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
51 AddStep(&TaskRemoveFiles::StepRemoveFinished);
52 AddStep(&TaskRemoveFiles::EndStep);
55 TaskRemoveFiles::~TaskRemoveFiles()
58 void TaskRemoveFiles::StepRemoveInstallationDirectory()
60 _D("StepRemoveInstallationDirectory started");
62 int ret = app2ext_get_app_location(m_context.tzPkgid.c_str());
64 // app2ext remove /opt/usr/apps[pkdid] directory in post_uninstall() function.
65 if (APP2EXT_SD_CARD == ret) {
66 _D("Remove external directory");
68 WidgetInstallToExtSingleton::Instance().initialize(m_context.tzPkgid);
69 WidgetInstallToExtSingleton::Instance().uninstallation();
70 WidgetInstallToExtSingleton::Instance().deinitialize();
72 Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
74 // Continue uninstall even fail to remove external directory.
75 // i.e.) SD card isn't inserted or unmounted.
76 // This behavior is recommended by platform(app2sd maintainer).
77 _E("Fail to remove external directory");
78 ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove external directory");
80 } else if (APP2EXT_NOT_INSTALLED != ret) {
81 _D("Removing directory");
83 std::string userAppsPath = WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
86 m_context.removeStarted = true;
87 bf::path widgetDir(m_context.installedPath);
90 std::string installedFullPath = bf::canonical(m_context.installedPath).string();
91 if (installedFullPath.find(userAppsPath) == std::string::npos ||
92 installedFullPath.size() <= userAppsPath.size()) {
93 _E("Invalid installed path : %s", installedFullPath.c_str());
96 JobWidgetUninstall::SecureRemove(widgetDir);
97 } Catch (bf::filesystem_error){
98 _E("Removing widget installation directory failed : %s", widgetDir.c_str());
101 bf::path dataDir(m_context.locations->getUserDataRootDir());
104 if (bf::exists(dataDir)) {
105 std::string dataRootPath = bf::canonical(dataDir).string();
106 if (dataRootPath.find(userAppsPath) == std::string::npos ||
107 dataRootPath.size() <= userAppsPath.size()) {
108 _E("Invalid data root path : %s", dataRootPath.c_str());
111 JobWidgetUninstall::SecureRemove(dataDir);
112 } Catch(bf::filesystem_error){
113 _W("%s is already removed", dataDir.c_str());
118 _E("app is not installed");
119 ThrowMsg(Exceptions::WidgetNotExist, "failed to get app location");
121 } Catch(Exception::RemoveFilesFailed) {
122 ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove directory");
124 m_context.job->UpdateProgress(
125 UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
126 "Widget INstallation Directory Removal Finished");
129 void TaskRemoveFiles::StepRemoveFinished()
131 _D("StepRemoveFinished finished");
133 m_context.job->UpdateProgress(
134 UninstallerContext::UNINSTALL_REMOVE_FINISHED,
135 "Widget remove steps Finished");
138 void TaskRemoveFiles::StartStep()
140 LOGI("--------- <TaskRemoveFiles> : START ----------");
143 void TaskRemoveFiles::EndStep()
145 LOGI("--------- <TaskRemoveFiles> : END ----------");
147 } //namespace WidgetUninstall