Creating root directory if not existing 23/38523/3
authorWojciech Kosowicz <w.kosowicz@samsung.com>
Tue, 21 Apr 2015 13:53:09 +0000 (15:53 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 22 Apr 2015 09:05:44 +0000 (02:05 -0700)
Change-Id: I7e6e6039ec9db1ab8e6bbcd52722a65479533786
Signed-off-by: Wojciech Kosowicz <w.kosowicz@samsung.com>
src/common/context_installer.cc
src/common/step/step_configure.cc
src/common/step/step_configure.h

index 17b2e2b..37714dd 100644 (file)
@@ -4,8 +4,6 @@
 // found in the LICENSE file.
 
 #include "common/context_installer.h"
-#include <boost/filesystem.hpp>
-#include <tzplatform_config.h>
 #include <unistd.h>
 #include <cstdlib>
 
@@ -16,15 +14,7 @@ namespace fs = boost::filesystem;
 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())
index 7ccebf3..3fe37f7 100644 (file)
@@ -4,7 +4,11 @@
 
 #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 {
@@ -14,6 +18,9 @@ const char *kStrEmpty = "";
 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());
@@ -34,5 +41,29 @@ Step::Status StepConfigure::process() {
   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
index 569e1f0..8228c3b 100644 (file)
@@ -21,6 +21,8 @@ class StepConfigure : public Step {
   Status clean() override { return Status::OK; }
   Status undo() override { return Status::OK; }
   Status precheck() override { return Status::OK; }
+ private:
+  bool SetupRootAppDirectory();
 
   SCOPE_LOG_TAG(Configure)
 };