tizen 2.4 release
[framework/web/wrt-installer.git] / src / jobs / widget_uninstall / task_delete_pkginfo.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_delete_pkginfo.cpp
18  * @author  Leerang Song(leerang.song@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for uninstaller delete package information
21  */
22
23 #include <string.h>
24 #include <widget_uninstall/task_delete_pkginfo.h>
25 #include <widget_uninstall/job_widget_uninstall.h>
26 #include <widget_uninstall/widget_uninstall_errors.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28 #include <pkgmgr/pkgmgr_parser.h>
29 #include <dpl/assert.h>
30 #include <boost/filesystem.hpp>
31 #include <dpl/log/secure_log.h>
32
33 namespace bf = boost::filesystem;
34
35 namespace Jobs {
36 namespace WidgetUninstall {
37 TaskDeletePkgInfo::TaskDeletePkgInfo(
38     UninstallerContext& context) :
39     DPL::TaskDecl<TaskDeletePkgInfo>(this),
40     m_context(context)
41 {
42     AddStep(&TaskDeletePkgInfo::StartStep);
43     AddStep(&TaskDeletePkgInfo::StepDeletePkgInfo);
44     AddStep(&TaskDeletePkgInfo::EndStep);
45 }
46
47 void TaskDeletePkgInfo::StartStep()
48 {
49     LOGI("--------- <TaskDeletePkgInfo> : START ----------");
50 }
51
52 void TaskDeletePkgInfo::EndStep()
53 {
54     LOGI("--------- <TaskDeletePkgInfo> : END ----------");
55 }
56
57 void TaskDeletePkgInfo::StepDeletePkgInfo()
58 {
59     std::ostringstream manifest_name;
60     manifest_name << m_context.tzPkgid << ".xml";
61     bf::path pre_manifest("/usr/share/packages");
62     pre_manifest /= manifest_name.str();
63     try {
64         if (!(bf::exists(m_context.manifestFile) == 0 && bf::exists(pre_manifest))) {
65             if (0 !=  pkgmgr_parser_parse_manifest_for_uninstallation(
66                         m_context.manifestFile.c_str(), NULL)) {
67                 _W("Manifest file failed to parse for uninstallation");
68             }
69         }
70         if (bf::remove_all(bf::path(m_context.manifestFile))) {
71             _D("Manifest file removed: %s", m_context.manifestFile.c_str());
72         } else {
73             _W("No manifest file found: %s", m_context.manifestFile.c_str());
74         }
75     } catch (const bf::filesystem_error& ex) {
76         _E("boost::filesystem::error: %s", ex.what());
77     }
78 }
79 } //namespace WidgetUninstall
80 } //namespace Jobs