#include <widget_uninstall/widget_uninstall_errors.h>
#include <dpl/wrt-dao-rw/widget_dao.h>
#include <dpl/wrt-dao-ro/widget_config.h>
-#include <dpl/wrt-dao-ro/vconf_config.h>
#include <dpl/assert.h>
#include <dpl/exception.h>
#include <dpl/utils/wrt_utility.h>
+#include <dpl/utils/path.h>
#include <ail.h>
#include <pkgmgr/pkgmgr_parser.h>
#include <errno.h>
#include <string.h>
#include <widget_install_to_external.h>
-#include <vconf.h>
namespace Jobs {
namespace WidgetUninstall {
using namespace WrtDB;
-namespace {
-const char * const VCONF_KEY_PREFIX = "file/private/";
-}
-
TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
DPL::TaskDecl<TaskRemoveFiles>(this),
m_context(context)
{
+ AddStep(&TaskRemoveFiles::StartStep);
AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
AddStep(&TaskRemoveFiles::StepRemoveManifest);
AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
- AddStep(&TaskRemoveFiles::StepRemoveVconf);
AddStep(&TaskRemoveFiles::StepRemoveFinished);
+ AddStep(&TaskRemoveFiles::EndStep);
}
TaskRemoveFiles::~TaskRemoveFiles()
void TaskRemoveFiles::StepRemoveInstallationDirectory()
{
- LogInfo("StepRemoveInstallationDirectory started");
+ LogDebug("StepRemoveInstallationDirectory started");
Try {
- if (APP2EXT_SD_CARD !=
- app2ext_get_app_location(m_context.tzPkgid.c_str()))
- {
+ int ret = app2ext_get_app_location(m_context.tzPkgid.c_str());
+
+ if (APP2EXT_INTERNAL_MEM == ret) {
LogDebug("Removing directory");
m_context.removeStarted = true;
- std::string widgetDir =
- m_context.locations->getPackageInstallationDir();
- if (!WrtUtilRemove(widgetDir)) {
- LogError("Removing widget installation directory failed");
+ DPL::Utils::Path widgetDir= m_context.installedPath;
+ Try{
+ DPL::Utils::Remove(widgetDir);
+ } Catch(DPL::Utils::Path::BaseException){
+ LogError("Removing widget installation directory failed : " <<
+ widgetDir.Fullpath());
}
- std::string dataDir = m_context.locations->getUserDataRootDir();
- if (!WrtUtilRemove(dataDir)) {
- LogWarning(dataDir + " is already removed");
+ DPL::Utils::Path dataDir(m_context.locations->getUserDataRootDir());
+ Try{
+ DPL::Utils::Remove(dataDir);
+ } Catch(DPL::Utils::Path::BaseException){
+ LogWarning(dataDir.Fullpath() << " is already removed");
}
- } else {
+ } else if (APP2EXT_SD_CARD == ret) {
LogDebug("Removing sdcard directory");
Try {
WidgetInstallToExtSingleton::Instance().initialize(m_context.tzPkgid);
Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
RemoveFilesFailed);
}
+ } else {
+ LogError("app is not installed");
+ ThrowMsg(Exceptions::WidgetNotExist, "failed to get app location");
}
} Catch(Exception::RemoveFilesFailed) {
ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove directory");
-
}
m_context.job->UpdateProgress(
UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
void TaskRemoveFiles::StepRemoveFinished()
{
- LogInfo("StepRemoveFinished finished");
+ LogDebug("StepRemoveFinished finished");
m_context.job->UpdateProgress(
UninstallerContext::UNINSTALL_REMOVE_FINISHED,
{
std::ostringstream manifest_name;
manifest_name << m_context.tzPkgid << ".xml";
- std::ostringstream destFile;
- destFile << "/opt/share/packages" << "/"; //TODO constant with path
- destFile << manifest_name.str();
- int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(
- destFile.str().c_str(), NULL);
- int ret2 = unlink(destFile.str().c_str());
- if (ret1 != 0) {
- LogWarning("Manifest file failed to parse for uninstallation");
+ DPL::Utils::Path destFile;
+ const DPL::Utils::Path PRELOAD_INSTALLED_PATH("/usr/apps");
+ const DPL::Utils::Path USR_PACKAGES_PATH("/usr/share/packages");
+ const DPL::Utils::Path OPT_PACKAGES_PATH("/opt/share/packages");
+ if (0 == (m_context.installedPath.Fullpath()).compare(0,
+ PRELOAD_INSTALLED_PATH.Fullpath().length(),
+ PRELOAD_INSTALLED_PATH.Fullpath())) {
+ LogDebug("This widget is preloaded.");
+ destFile = USR_PACKAGES_PATH;
+ } else {
+ destFile = OPT_PACKAGES_PATH;
}
- if (ret2 != 0) {
- LogWarning("No manifest file found: " << destFile.str());
+ destFile /= manifest_name.str();
+ DPL::Utils::Path pre_manifest = USR_PACKAGES_PATH;
+ pre_manifest /= manifest_name.str();
+
+ if (!(destFile.Exists() == 0 && pre_manifest.Exists())) {
+ int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(
+ destFile.Fullpath().c_str(), NULL);
+ if (ret1 != 0) {
+ LogWarning("Manifest file failed to parse for uninstallation");
+ }
+ }
+ if (!DPL::Utils::TryRemove(destFile)) {
+ LogWarning("No manifest file found: " << destFile.Fullpath());
} else {
- LogDebug("Manifest file removed: " << destFile.str());
+ LogDebug("Manifest file removed: " << destFile.Fullpath());
}
}
WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
LogDebug("Removing external locations:");
WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
- FOREACH(path, externalPaths)
+ FOREACH(file, externalPaths)
{
- if (WrtUtilFileExists(*path)) {
- LogDebug(" -> " << *path);
- int ret = remove(path->c_str());
- if (ret != 0) {
- LogError(
- "Failed to remove the file: " << path->c_str() <<
- " with error: " << strerror(errno));
- }
- } else if (WrtUtilDirExists(*path)) {
- LogDebug(" -> " << *path);
- if (!WrtUtilRemove(*path)) {
- Throw(
- Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
- RemoveFilesFailed);
+ DPL::Utils::Path path(*file);
+ if(path.Exists()){
+ if(path.IsFile()){
+ LogDebug(" -> " << path.Fullpath());
+ Try{
+ DPL::Utils::Remove(path);
+ }Catch(DPL::Utils::Path::BaseException){
+ LogError("Failed to remove the file: " << path.Fullpath());
+ }
+ } else if (path.IsDir()){
+ LogDebug(" -> " << path.Fullpath());
+ Try{
+ DPL::Utils::Remove(path);
+ }Catch(DPL::Utils::Path::BaseException){
+ Throw(Jobs::WidgetUninstall::TaskRemoveFiles::
+ Exception::RemoveFilesFailed);
+ }
}
- } else {
- LogWarning(" -> " << *path << "(no such a path)");
+ }else{
+ LogWarning(" -> " << path.Fullpath() << "(no such a path)");
}
}
dao.unregisterAllExternalLocations();
}
}
-void TaskRemoveFiles::StepRemoveVconf()
+void TaskRemoveFiles::StartStep()
{
- if (!m_context.removeAbnormal) {
- std::string key =
- WrtDB::VconfConfig::GetVconfKeyRootPath(DPL::FromUTF8String(m_context.
- tzAppid));
- if (vconf_unset_recursive(key.c_str())) {
- LogError("Fail to unset vconf file");
- } else {
- LogDebug("vconf file is removed");
- }
- }
+ LogDebug("--------- <TaskRemoveFiles> : START ----------");
+}
+
+void TaskRemoveFiles::EndStep()
+{
+ LogDebug("--------- <TaskRemoveFiles> : END ----------");
}
} //namespace WidgetUninstall
} //namespace Jobs