--- /dev/null
+// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/pkgmgr_dependency.h"
+
+#include <manifest_parser/utils/version_number.h>
+
+#include "common/request.h"
+#include "common/utils/glist_range.h"
+
+namespace {
+
+const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+int CompareVersion(const std::string& a, const std::string& b) {
+ utils::VersionNumber a_ver(a);
+ utils::VersionNumber b_ver(b);
+
+ return a_ver.Compare(b_ver);
+}
+
+} // namespace
+
+namespace common_installer {
+
+bool SatisfyDependencyTo(GList* dependencies, const uid_t uid,
+ const RequestMode mode) {
+ bool satisfy = true;
+ for (const auto& dep : GListRange<dependency_x*>(dependencies)) {
+ // check only requires pkgs
+ if (strcmp(dep->type, "requires"))
+ continue;
+ PkgQueryInterface pkg_query(dep->depends_on, uid);
+ if (!pkg_query.IsPackageInstalled(mode)) {
+ LOG(ERROR) << dep->depends_on << " is required but not installed!";
+ satisfy = false;
+ } else if (dep->required_version &&
+ (CompareVersion(pkg_query.Version(), dep->required_version) < 0)) {
+ LOG(ERROR) << "Same or higher version (" << dep->required_version
+ << ") of " << dep->depends_on << " is required "
+ << "but current version of installed package is: "
+ << pkg_query.Version();
+ satisfy = false;
+ }
+ }
+
+ return satisfy;
+}
+
+bool SatisfyDependencyFrom(const std::string pkgid, const std::string version,
+ const uid_t uid, const bool is_remove) {
+ PkgQueryInterface pkg_query(pkgid, uid);
+ std::vector<PkgQueryInterface::DependencyInfo> depends_on;
+ if (!pkg_query.PackagesDependsOn(&depends_on)) {
+ LOG(ERROR) << "Can't get Package Depends On";
+ return false;
+ }
+
+ bool satisfy = true;
+ for (const auto& dep : depends_on) {
+ if (std::get<1>(dep) != pkgid)
+ continue;
+ if (std::get<2>(dep) != "requires")
+ continue;
+ if (is_remove) {
+ LOG(ERROR) << std::get<0>(dep) << " requires this package";
+ satisfy = false;
+ } else {
+ if (CompareVersion(version, std::get<3>(dep)) < 0) {
+ LOG(ERROR) << std::get<0>(dep)
+ << " requires same or higher version (" << std::get<3>(dep)
+ << ") of this package (" << pkgid << ") but the version "
+ << "of this package trying to update is : " << version;
+ satisfy = false;
+ }
+ }
+ }
+
+ return satisfy;
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_PKGMGR_DEPENDENCY_H_
+#define COMMON_PKGMGR_DEPENDENCY_H_
+
+#include <glib.h>
+
+#include <string>
+#include <vector>
+
+#include "common/installer_context.h"
+#include "common/pkgmgr_query.h"
+
+namespace common_installer {
+
+bool SatisfyDependencyTo(GList* dependencies, const uid_t uid,
+ const RequestMode mode);
+bool SatisfyDependencyFrom(const std::string pkgid, const std::string version,
+ const uid_t uid, const bool is_remove);
+
+} // namespace common_installer
+
+#endif // COMMON_PKGMGR_DEPENDENCY_H_
#include <string>
#include <vector>
+#include "common/pkgmgr_dependency.h"
#include "common/pkgmgr_query.h"
#include "common/utils/glist_range.h"
#include "common/utils/user_util.h"
const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-int CompareVersion(const std::string& a, const std::string& b) {
- utils::VersionNumber a_ver(a);
- utils::VersionNumber b_ver(b);
-
- return a_ver.Compare(b_ver);
-}
-
} // namespace
namespace common_installer {
if (getuid () == 0)
return Status::OK;
- bool installable = true;
- manifest_x* manifest = context_->manifest_data.get();
- for (const auto& dep : GListRange<dependency_x*>(manifest->dependencies)) {
- // check only requires pkgs
- if (strcmp(dep->type, "requires"))
- continue;
- PkgQueryInterface pkg_query(dep->depends_on, context_->uid.get());
- if (!pkg_query.IsPackageInstalled(context_->request_mode.get())) {
- LOG(ERROR) << dep->depends_on << " is required but not installed!";
- installable = false;
- } else if (dep->required_version &&
- (CompareVersion(manifest->version, dep->required_version) < 0)) {
- LOG(ERROR) << "Same or higher version (" << dep->required_version
- << ") of " << dep->depends_on
- << " is required but current version of installed package is: "
- << pkg_query.Version();
- installable = false;
- }
- }
-
- if (!installable)
+ if (!SatisfyDependencyTo(context_->manifest_data.get()->dependencies,
+ context_->uid.get(), context_->request_mode.get()))
return Status::OPERATION_NOT_ALLOWED;
return Status::OK;
#include <vector>
#include "common/app_installer.h"
+#include "common/pkgmgr_dependency.h"
#include "common/pkgmgr_query.h"
namespace common_installer {
if (getuid() == 0)
return Status::OK;
- std::vector<PkgQueryInterface::DependencyInfo> depends_on;
- if (!pkg_query.PackagesDependsOn(&depends_on))
- return Status::INVALID_VALUE;
-
- int break_count = 0;
- for (const auto& dep : depends_on) {
- if (std::get<1>(dep) != context_->pkgid.get())
- continue;
- if (std::get<2>(dep) == "requires") {
- LOG(ERROR) << std::get<0>(dep) << " requires this package";
- ++break_count;
- }
- }
-
- if (break_count)
+ if (!SatisfyDependencyFrom(context_->pkgid.get(), "",
+ context_->uid.get(), true))
return Status::OPERATION_NOT_ALLOWED;
return Status::OK;
#include <string>
#include <vector>
+#include "common/pkgmgr_dependency.h"
#include "common/pkgmgr_query.h"
-namespace {
-
-int CompareVersion(const std::string& a, const std::string& b) {
- utils::VersionNumber a_ver(a);
- utils::VersionNumber b_ver(b);
-
- return a_ver.Compare(b_ver);
-}
-
-} // namespace
-
namespace common_installer {
namespace pkgmgr {
if (getuid() == 0)
return Status::OK;
- std::vector<PkgQueryInterface::DependencyInfo> depends_on;
- if (!pkg_query.PackagesDependsOn(&depends_on))
- return Status::INVALID_VALUE;
-
- int break_count = 0;
- manifest_x* manifest = context_->manifest_data.get();
- for (const auto& dep : depends_on) {
- if (std::get<1>(dep) != context_->pkgid.get())
- continue;
- if (std::get<2>(dep) == "requires") {
- if (CompareVersion(manifest->version, std::get<3>(dep)) < 0) {
- LOG(ERROR) << std::get<0>(dep)
- << " requires higher version of this package";
- ++break_count;
- }
- }
- }
-
- if (break_count)
+ if (!SatisfyDependencyFrom(context_->pkgid.get(),
+ context_->manifest_data.get()->version,
+ context_->uid.get(), false))
return Status::OPERATION_NOT_ALLOWED;
return Status::OK;