#include <widget_uninstall/uninstaller_context.h>
#include <dpl/wrt-dao-rw/widget_dao.h>
#include <dpl/wrt-dao-ro/widget_config.h>
-#include <errno.h>
#include <dpl/assert.h>
#include <dpl/utils/wrt_utility.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <dirent.h>
#include <ail.h>
-#include <dpl/utils/wrt_utility.h>
#include <pkgmgr/pkgmgr_parser.h>
namespace Jobs {
using namespace WrtDB;
-void TaskRemoveFiles::ReadDir(const std::string& path,
- std::list<std::string>& filesList)
-{
- LogInfo("Reading directory " << path);
- DIR* dir = NULL;
- struct dirent* ptr = NULL;
- dir = opendir(path.c_str());
- std::string delim = "";
-
- // adding / for path to directory to build a proper path to file under directory
- if (path[path.size() - 1] != '/') {
- delim = "/";
- }
-
- if (dir) {
- while ((ptr = readdir(dir)) != NULL) {
- if ((!strcmp(ptr->d_name, ".")) || (!strcmp(ptr->d_name, ".."))) {
- LogPedantic("Omiting " << ptr->d_name);
- continue;
- }
- std::string childPath = path + delim + ptr->d_name;
-
- struct stat st;
- if (0 != lstat(childPath.c_str(), &st)) {
- switch (errno) {
- case EACCES:
- LogWarning(
- "EACCESS Error occured during lstat with path: " <<
- childPath);
- continue;
- case EBADF:
- LogWarning(
- "EBADF Error occured during lstat with path: " <<
- childPath);
- continue;
- case ENOENT:
- LogWarning(
- "ENOENT Error occured during lstat with path: " <<
- childPath);
- continue;
- case ENOTDIR:
- LogWarning(
- "ENOTDIR Error occured during lstat with path: " <<
- childPath);
- continue;
- default:
- LogWarning(
- "Unknown Error occured during lstat with path: " <<
- childPath);
- continue;
- }
- } else {
- if (S_ISDIR(st.st_mode)) {
- LogPedantic(
- "Calling ReadDir in recursive way " << childPath);
- ReadDir(childPath, filesList);
- } else if (S_ISREG(st.st_mode) ||
- S_ISCHR(st.st_mode) ||
- S_ISBLK(st.st_mode) ||
- S_ISFIFO(st.st_mode) ||
- S_ISLNK(st.st_mode) ||
- S_ISSOCK(st.st_mode)) {
- LogPedantic("Adding to list " << childPath);
- filesList.push_front(childPath);
- } else {
- LogWarning("Uknown file type ??");
- }
- }
- }
- closedir(dir);
- } else if (errno == ENOTDIR) {
- LogDebug("Adding to list " << path);
- filesList.push_front(path);
- } else {
- LogWarning("Unknown error");
- }
-}
-
TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
DPL::TaskDecl<TaskRemoveFiles>(this),
m_context(context)
{
- AddStep(&TaskRemoveFiles::StepPrepare);
- AddStep(&TaskRemoveFiles::StepRemoveOneFile);
- AddStep(&TaskRemoveFiles::StepRemoveDirectories);
+ AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
//AddStep(&TaskRemoveFiles::StepRemoveDesktop);
AddStep(&TaskRemoveFiles::StepRemoveManifest);
AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
{
}
-void TaskRemoveFiles::StepPrepare()
+void TaskRemoveFiles::StepRemoveInstallationDirectory()
{
- LogInfo("StepPrepare started");
-
- std::ostringstream widgetDir;
-
- widgetDir << m_context.locations->getPackageInstallationDir() << "/";
-
- uninstRootDir = widgetDir.str();
- ReadDir(uninstRootDir, filesList);
+ LogInfo("StepRemoveInstallationDirectory started");
- LogInfo("StepPrepare finished");
-
- m_context.job->UpdateProgress(
- UninstallerContext::UNINSTALL_REMOVE_PREPARE,
- "Widget remove prepare Finished");
m_context.removeStarted = true;
-}
-
-void TaskRemoveFiles::StepRemoveOneFile()
-{
- if (filesList.size() > 0) {
- LogDebug("Removing " << filesList.front());
- if (0 != unlink(filesList.front().c_str())) {
- LogWarning("Failed to remove file" << filesList.front());
- }
- filesList.pop_front();
- SwitchToStep(&TaskRemoveFiles::StepRemoveOneFile);
- } else {
- m_context.removeFinished = true;
- }
-
- m_context.job->UpdateProgress(
- UninstallerContext::UNINSTALL_REMOVE_ONEFILE,
- "Widget remove onefile Finished");
-}
-
-void TaskRemoveFiles::StepRemoveDirectories()
-{
- using namespace WrtDB;
- LogInfo("StepRemoveDirectories started");
-
- if (!WrtUtilRemove(uninstRootDir)) {
- LogWarning("Failed to remove directory" << uninstRootDir);
+ std::string widgetDir =
+ m_context.locations->getPackageInstallationDir();
+ if(!WrtUtilRemove(widgetDir)){
+ LogWarning("Removing widget installation directory failed");
}
- LogInfo("StepRemoveDirectories finished");
-
m_context.job->UpdateProgress(
- UninstallerContext::UNINSTALL_REMOVE_DIRECTORIES,
- "Widget remove directories Finished");
+ UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
+ "Widget INstallation Directory Removal Finished");
}
void TaskRemoveFiles::StepRemoveFinished()