[Release] wrt-installer_0.0.73
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_private_storage.cpp
index f0216e7..8d9934f 100644 (file)
@@ -25,6 +25,7 @@
 #include <grp.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <string>
 
@@ -32,7 +33,7 @@
 #include <dpl/errno_string.h>
 
 #include <dpl/wrt-dao-ro/widget_config.h>
-#include <dpl/utils/file_utils.h>
+#include <dpl/utils/wrt_utility.h>
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_context.h>
 #include <widget_install/widget_install_errors.h>
@@ -65,13 +66,12 @@ void TaskPrivateStorage::StepCreateDirectory()
     std::ostringstream widgetPath;
     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
     if(!pkgname.IsNull()) {
-        widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/";
-        widgetPath << pkgname << "/";
+        widgetPath << m_context.locations->getPackageInstallationDir() << "/";
     } else {
         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
     }
 
-    if (access(widgetPath.str().c_str(), W_OK | X_OK) != 0) {
+    if (euidaccess(widgetPath.str().c_str(), W_OK | X_OK) != 0) {
         ThrowMsg(Exceptions::InternalError, DPL::GetErrnoString());
     }
 
@@ -79,8 +79,12 @@ void TaskPrivateStorage::StepCreateDirectory()
     storagePath << widgetPath.str().c_str()
                 << GlobalConfig::GetWidgetPrivateStoragePath();
 
-    if (access(storagePath.str().c_str(), F_OK) != 0) {
-        FileUtils::MakePath(storagePath.str(), PRIVATE_STORAGE_MODE);
+    if (euidaccess(storagePath.str().c_str(), F_OK) != 0) {
+        if(!WrtUtilMakeDir(storagePath.str(), PRIVATE_STORAGE_MODE)){
+            LogError("Failed to create directory for private storage");
+            ThrowMsg(Exceptions::InternalError,
+                    "Failed to create directory for private storage");
+        }
         // '5000' is default uid, gid for applications.
         // So installed applications should be launched as process of uid '5000'.
         // the process can access private directory 'data' of itself.
@@ -91,8 +95,22 @@ void TaskPrivateStorage::StepCreateDirectory()
             ThrowMsg(Exceptions::InternalError,
                  "Chown to invaild user");
         }
-    } else if (access(storagePath.str().c_str(), W_OK | R_OK | X_OK) == 0) {
+    } else if (euidaccess(storagePath.str().c_str(), W_OK | R_OK | X_OK) == 0) {
         LogInfo("Private storage already exists.");
+        // Even if private directory already is created, private dircetory
+        // should change owner.
+        if(chown(storagePath.str().c_str(),
+                 WEBAPP_DEFAULT_UID,
+                 WEBAPP_DEFAULT_GID) != 0)
+        {
+            ThrowMsg(Exceptions::InternalError,
+                 "Chown to invaild user");
+        }
+        if(chmod(storagePath.str().c_str(), PRIVATE_STORAGE_MODE) != 0) {
+            ThrowMsg(Exceptions::InternalError,
+                 "chmod to 0700");
+        }
+
     } else {
         ThrowMsg(Exceptions::InternalError,
                  "No access to private storage.");