88db8e213b02fbc478d8c792de4317f3e4a96d34
[framework/web/wrt-installer.git] / src_mobile / 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 <dpl/utils/wrt_utility.h>
31 #include <dpl/utils/path.h>
32 #include <installer_log.h>
33
34 namespace Jobs {
35 namespace WidgetUninstall {
36 TaskDeletePkgInfo::TaskDeletePkgInfo(
37     UninstallerContext& context) :
38     DPL::TaskDecl<TaskDeletePkgInfo>(this),
39     m_context(context)
40 {
41     AddStep(&TaskDeletePkgInfo::StartStep);
42     AddStep(&TaskDeletePkgInfo::StepDeletePkgInfo);
43     AddStep(&TaskDeletePkgInfo::EndStep);
44 }
45
46 void TaskDeletePkgInfo::StartStep()
47 {
48     _D("--------- <TaskDeletePkgInfo> : START ----------");
49 }
50
51 void TaskDeletePkgInfo::EndStep()
52 {
53     _D("--------- <TaskDeletePkgInfo> : END ----------");
54 }
55
56 void TaskDeletePkgInfo::StepDeletePkgInfo()
57 {
58     std::ostringstream manifest_name;
59     manifest_name << m_context.tzPkgid << ".xml";
60     DPL::Utils::Path pre_manifest("/usr/share/packages");
61     pre_manifest /= manifest_name.str();
62
63     if (!(m_context.manifestFile.Exists() == 0 && pre_manifest.Exists())) {
64         if (0 !=  pkgmgr_parser_parse_manifest_for_uninstallation(
65                     m_context.manifestFile.Fullpath().c_str(), NULL)) {
66             _W("Manifest file failed to parse for uninstallation");
67         }
68     }
69     if (!DPL::Utils::TryRemove(m_context.manifestFile)) {
70         _W("No manifest file found: %s", m_context.manifestFile.Fullpath().c_str());
71     } else {
72         _D("Manifest file removed: %s", m_context.manifestFile.Fullpath().c_str());
73     }
74 }
75 } //namespace WidgetUninstall
76 } //namespace Jobs