#include "common/step/configuration/step_configure.h"
-#include <boost/filesystem/path.hpp>
-
#include <pkgmgr-info.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <tzplatform_config.h>
+#include <filesystem>
#include <memory>
+#include <optional>
#include <string>
+#include <system_error>
#include <utility>
#include "common/utils/pkgmgr_query.h"
#include "common/utils/user_util.h"
#include "common/utils/request.h"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace common_installer {
namespace configuration {
const char kStrEmpty[] = "";
const char kAppFWUser[] = "app_fw";
+const char kRpmPkgType[] = "rpm";
+const char kRpmInstaller[] = "tpk";
StepConfigure::StepConfigure(InstallerContext* context, PkgMgrPtr pkgmgr)
: Step(context),
RequestType request_type = context_->request_type.get();
switch (request_type) {
case RequestType::Install:
- case RequestType::Update:
+ case RequestType::Update: {
context_->file_path.set(pkgmgr_->GetRequestInfo(context_->index.get()));
if (!pkgmgr_->GetTepPath().empty()) {
context_->tep_path.set(pkgmgr_->GetTepPath());
context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
}
+ context_->pkgid.set(GetPkgIdFromFile());
break;
+ }
case RequestType::PartialUninstall:
case RequestType::Uninstall:
if (request_type == RequestType::PartialUninstall)
break;
case RequestType::Reinstall:
context_->unpacked_dir_path.set(
- bf::path(tzplatform_getenv(TZ_SDK_TOOLS)) / "tmp" /
+ fs::path(tzplatform_getenv(TZ_SDK_TOOLS)) / "tmp" /
pkgmgr_->GetRequestInfo(context_->index.get()));
context_->pkgid.set(pkgmgr_->GetRequestInfo(context_->index.get()));
context_->file_path.set(kStrEmpty);
pkgmgr_->GetRecoveryCleanup()));
break;
case RequestType::MountInstall:
- case RequestType::MountUpdate:
+ case RequestType::MountUpdate: {
context_->file_path.set(pkgmgr_->GetRequestInfo(context_->index.get()));
if (!pkgmgr_->GetTepPath().empty()) {
context_->tep_path.set(pkgmgr_->GetTepPath());
context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
}
+ context_->pkgid.set(GetPkgIdFromFile());
break;
+ }
case RequestType::ManifestPartialInstall:
case RequestType::ManifestPartialUpdate:
case RequestType::ManifestDirectInstall:
request_type == RequestType::ManifestPartialUpdate)
SetupIsPartialRW();
context_->pkgid.set(pkgmgr_->GetRequestInfo(context_->index.get()));
- bf::path xml_path =
- bf::path(getUserManifestPath(context_->uid.get(),
+ fs::path xml_path =
+ fs::path(getUserManifestPath(context_->uid.get(),
context_->is_readonly_package.get()))
- / bf::path(context_->pkgid.get());
+ / fs::path(context_->pkgid.get());
xml_path += ".xml";
context_->unpacked_dir_path.set(context_->GetPkgPath());
context_->xml_path.set(xml_path);
break;
}
- case RequestType::ReadonlyUpdateInstall:
+ case RequestType::ReadonlyUpdateInstall: {
context_->file_path.set(pkgmgr_->GetRequestInfo(context_->index.get()));
if (!pkgmgr_->GetTepPath().empty()) {
context_->tep_path.set(pkgmgr_->GetTepPath());
context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
}
+ context_->pkgid.set(GetPkgIdFromFile());
break;
+ }
case RequestType::ReadonlyUpdateUninstall: {
context_->pkgid.set(pkgmgr_->GetRequestInfo(context_->index.get()));
- bf::path original_path =
- bf::path(tzplatform_getenv(TZ_SYS_RO_APP)) / context_->pkgid.get();
+ fs::path original_path =
+ fs::path(tzplatform_getenv(TZ_SYS_RO_APP)) / context_->pkgid.get();
context_->unpacked_dir_path.set(original_path);
context_->file_path.set(kStrEmpty);
SetupIsKeepRWData();
return Status::CONFIG_ERROR;
}
+ if (!CheckInvalidBackendUsage())
+ return Status::OPERATION_NOT_ALLOWED;
+
LOG(INFO) << "Request Type: " << GetRequestTypeString(request_type);
return Status::OK;
if (getuid() == 0)
return Status::OK;
- boost::optional<uid_t> appfw_uid = GetUidByUserName(kAppFWUser);
+ std::optional<uid_t> appfw_uid = GetUidByUserName(kAppFWUser);
if (!appfw_uid)
return Status::ERROR;
context_->root_application_path.set(root_app_path);
}
- if (!boost::filesystem::exists(context_->root_application_path.get())) {
- boost::system::error_code error;
- boost::filesystem::create_directories(
- context_->root_application_path.get());
+ if (!fs::exists(context_->root_application_path.get())) {
+ std::error_code error;
+ fs::create_directories(context_->root_application_path.get());
if (error) {
LOG(ERROR) << "Cannot create directory: "
<< context_->root_application_path.get();
}
}
+std::string StepConfigure::GetPkgIdFromFile() {
+ auto app_query_interface = pkgmgr_->GetAppQueryInterface();
+ if (!app_query_interface)
+ return "";
+
+ return app_query_interface->GetPkgId(
+ pkgmgr_->GetRequestInfo(context_->index.get()));
+}
+
+bool StepConfigure::CheckInvalidBackendUsage() {
+ if (context_->pkgid.get().empty())
+ return true;
+
+ PkgQueryInterface pkg_query(context_->pkgid.get().c_str(),
+ context_->uid.get());
+ if (!pkg_query.IsValid()) {
+ LOG(INFO) << "pkg[" << context_->pkgid.get()
+ << "] is not installed, skip checking backend with installed pkg";
+ return true;
+ }
+
+ const std::string& backend_type = context_->pkg_type.get();
+ std::string installed_pkg_type = pkg_query.Type();
+ if (installed_pkg_type == kRpmPkgType)
+ installed_pkg_type = kRpmInstaller;
+
+ if (installed_pkg_type != backend_type) {
+ LOG(ERROR) << "Wrong use of backend : package's type [" << pkg_query.Type()
+ << "] mismatched backend [" << backend_type << "]";
+ return false;
+ }
+
+ return true;
+}
+
} // namespace configuration
} // namespace common_installer