// found in the LICENSE file.
#include "common/context_installer.h"
-#include <boost/filesystem.hpp>
-#include <tzplatform_config.h>
#include <unistd.h>
#include <cstdlib>
ContextInstaller::ContextInstaller()
: manifest_data(static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)))),
old_manifest_data(nullptr),
- uid(getuid()) {
-
- std::string root_app_path =
- uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
- ? tzplatform_getenv(TZ_USER_APP)
- : tzplatform_getenv(TZ_SYS_RW_APP);
-
- root_application_path.set(root_app_path);
-}
+ uid(getuid()) {}
ContextInstaller::~ContextInstaller() {
if (manifest_data.get())
#include "common/step/step_configure.h"
+#include <tzplatform_config.h>
+#include <string>
+
#include "common/pkgmgr_interface.h"
+#include "utils/file_util.h"
namespace common_installer {
namespace configure {
Step::Status StepConfigure::process() {
PkgMgrPtr pkgmgr = PkgMgrInterface::Instance();
+ if (!SetupRootAppDirectory())
+ return Status::ERROR;
+
switch (pkgmgr->GetRequestType()) {
case PkgMgrInterface::Type::Install:
context_->file_path.set(pkgmgr->GetRequestInfo());
return Status::OK;
}
+bool StepConfigure::SetupRootAppDirectory() {
+ if (context_->root_application_path.get().empty()) {
+ std::string root_app_path =
+ context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+ ? tzplatform_getenv(TZ_USER_APP)
+ : tzplatform_getenv(TZ_SYS_RW_APP);
+ if (root_app_path.empty())
+ return false;
+
+ 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 (error) {
+ LOG(ERROR) << "Cannot create directory: "
+ << context_->root_application_path.get();
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace configure
} // namespace common_installer