Block different type installation with same pkgid
[platform/core/appfw/app-installers.git] / src / common / step / pkgmgr / step_check_removable.cc
1 // Copyright (c) 2016 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_check_removable.h"
6
7 #include <sys/types.h>
8 #include <unistd.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "common/installer/app_installer.h"
14 #include "common/pkgmgr_dependency.h"
15 #include "common/utils/pkgmgr_query.h"
16
17 namespace common_installer {
18 namespace pkgmgr {
19
20 Step::Status StepCheckRemovable::process() {
21   if (context_->force_remove.get())
22       return Status::OK;
23
24   PkgQueryInterface pkg_query(context_->pkgid.get().c_str(),
25       context_->uid.get());
26   if (!pkg_query.IsValid()) {
27     LOG(ERROR) << "This package is not installed";
28     return Status::INVALID_VALUE;
29   }
30   bool removable = pkg_query.IsRemovablePackage();
31   if (pkg_query.GetLastOperationError() != PMINFO_R_OK)
32     return Status::INVALID_VALUE;
33
34   if (!removable) {
35     LOG(ERROR) << "This package is not removable";
36     return Status::OPERATION_NOT_ALLOWED;
37   }
38
39   return Status::OK;
40 }
41
42 Step::Status StepCheckRemovable::precheck() {
43   if (context_->pkgid.get().empty())
44     return Status::INVALID_VALUE;
45   return Status::OK;
46 }
47
48 }  // namespace pkgmgr
49 }  // namespace common_installer