Remove unused parameter and related codes
[platform/core/appfw/app-installers.git] / src / common / step / pkgmgr / step_unregister_app.cc
1 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/step/pkgmgr/step_unregister_app.h"
6
7 #include <unistd.h>
8
9 #include <boost/filesystem.hpp>
10 #include <boost/system/error_code.hpp>
11 #include <pkgmgr_installer.h>
12 #include <vcore/Certificate.h>
13
14 #include <cassert>
15 #include <string>
16
17 #include "common/pkgmgr_registration.h"
18 #include "common/pkgmgr_query.h"
19 #include "common/utils/file_util.h"
20
21 namespace common_installer {
22 namespace pkgmgr {
23
24 namespace bs = boost::system;
25 namespace bf = boost::filesystem;
26
27 Step::Status StepUnregisterApplication::precheck() {
28   if (context_->pkgid.get().empty()) {
29     LOG(ERROR) << "pkgid attribute is empty";
30     return Status::PACKAGE_NOT_FOUND;
31   }
32   if (context_->xml_path.get().empty()) {
33     LOG(ERROR) << "xml_path attribute is empty";
34     return Status::MANIFEST_NOT_FOUND;
35   }
36   if (!boost::filesystem::exists(context_->xml_path.get())) {
37     LOG(ERROR) << "xml_path ("
38                << context_->xml_path.get()
39                << ") path does not exist";
40     return Status::MANIFEST_NOT_FOUND;
41   }
42
43   return Step::Status::OK;
44 }
45
46 bool StepUnregisterApplication::BackupCertInfo() {
47   std::string base64 = QueryCertificateAuthorCertificate(context_->pkgid.get(),
48                                                          context_->uid.get());
49   if (!base64.empty()) {
50     CertificateInfo certificate_info;
51     try {
52       certificate_info.author_certificate.set(ValidationCore::CertificatePtr(
53           new ValidationCore::Certificate(
54               base64,
55               ValidationCore::Certificate::FormType::FORM_BASE64)));
56     } catch (const ValidationCore::Certificate::Exception::Base &e) {
57       LOG(ERROR) << "Exception in cert-svc-vcore Certificate "
58                  << "Dump : " << e.DumpToString();
59       return false;
60     }
61     context_->certificate_info.set(certificate_info);
62   }
63
64   return true;
65 }
66
67 Step::Status StepUnregisterApplication::process() {
68   // Prepare certificate info for rollback operations
69   if (!BackupCertInfo()) {
70     LOG(ERROR) << "Failed to backup cert info";
71   }
72
73   if (!UnregisterAppInPkgmgr(context_->manifest_data.get(),
74                              context_->pkgid.get(),
75                              context_->uid.get(),
76                              context_->request_mode.get())) {
77     LOG(ERROR) << "Failed to unregister package into database";
78   }
79
80   // remove manifest file
81   bs::error_code error;
82   bf::remove(context_->xml_path.get(), error);
83
84   LOG(DEBUG) << "Successfully unregister the application";
85
86   return Status::OK;
87 }
88
89 Step::Status StepUnregisterApplication::undo() {
90   if (!RegisterAppInPkgmgr(context_->manifest_data.get(),
91                            context_->pkgid.get(),
92                            context_->certificate_info.get(),
93                            context_->uid.get(),
94                            context_->request_mode.get())) {
95     LOG(ERROR) << "Failed to restore the app registration in pkgmgr";
96     return Step::Status::REGISTER_ERROR;
97   }
98
99   LOG(INFO) << "Successfully restored the app registration in pkgmgr";
100   return Status::OK;
101 }
102
103 }  // namespace pkgmgr
104 }  // namespace common_installer