add to create share directory
authorSoyoung Kim <sy037.kim@samsung.com>
Thu, 22 Nov 2012 04:58:37 +0000 (13:58 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Wed, 5 Dec 2012 05:33:37 +0000 (14:33 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] create share directory
[SCMRequest] this commit have to be imported with wrt-commons.

Change-Id: I20dc86748a5527382a1a6a6a8e73567c66520554

src/jobs/widget_install/task_file_manipulation.cpp
src/jobs/widget_install/task_file_manipulation.h
src/misc/widget_location.cpp
src/misc/widget_location.h

index 2a1400d..5d981ea 100644 (file)
@@ -35,6 +35,7 @@
 
 namespace {
 const mode_t PRIVATE_STORAGE_MODE = 0700;
+const mode_t SHARE_MODE = 0705;
 }
 
 using namespace WrtDB;
@@ -47,6 +48,7 @@ TaskFileManipulation::TaskFileManipulation(InstallerContext& context) :
 {
     AddStep(&TaskFileManipulation::StepCreateDirs);
     AddStep(&TaskFileManipulation::StepCreatePrivateStorageDir);
+    AddStep(&TaskFileManipulation::StepCreateShareDir);
     AddStep(&TaskFileManipulation::StepRenamePath);
 
     AddAbortStep(&TaskFileManipulation::StepAbortRenamePath);
@@ -124,6 +126,49 @@ void TaskFileManipulation::StepCreatePrivateStorageDir()
     }
 }
 
+void TaskFileManipulation::StepCreateShareDir()
+{
+    std::string sharePath = m_context.locations->getShareDir();
+
+    if (euidaccess(sharePath.c_str(), F_OK) != 0) {
+        if(!WrtUtilMakeDir(sharePath, SHARE_MODE)){
+            LogError("Failed to create directory for share");
+            ThrowMsg(Exceptions::InternalError,
+                    "Failed to create directory for share");
+        }
+        // '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.
+        if(chown(sharePath.c_str(),
+                 WEBAPP_DEFAULT_UID,
+                 WEBAPP_DEFAULT_GID) != 0)
+        {
+            ThrowMsg(Exceptions::InternalError,
+                 "Chown to invaild user");
+        }
+    } else if (euidaccess(sharePath.c_str(), W_OK | R_OK | X_OK) == 0) {
+        LogInfo("Share directory already exists.");
+        // Even if share directory already is created, share dircetory
+        // should change owner.
+        if(chown(sharePath.c_str(),
+                 WEBAPP_DEFAULT_UID,
+                 WEBAPP_DEFAULT_GID) != 0)
+        {
+            ThrowMsg(Exceptions::InternalError,
+                 "Chown to invaild user");
+        }
+        if(chmod(sharePath.c_str(), SHARE_MODE) != 0) {
+            ThrowMsg(Exceptions::InternalError,
+                 "chmod to 0700");
+        }
+
+    } else {
+        ThrowMsg(Exceptions::InternalError,
+                 "No access to private storage.");
+    }
+
+}
+
 void TaskFileManipulation::StepRenamePath()
 {
     std::string instDir;
index 429b0fb..9bdfe9c 100644 (file)
@@ -37,6 +37,7 @@ class TaskFileManipulation :
     void StepCreateDirs();
     void StepRenamePath();
     void StepCreatePrivateStorageDir();
+    void StepCreateShareDir();
 
     void StepAbortRenamePath();
 
index 31b5d17..f495418 100644 (file)
@@ -159,6 +159,12 @@ std::string WidgetLocation::getPrivateStorageDir() const
         WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
 }
 
+std::string WidgetLocation::getShareDir() const
+{
+    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+            + m_pkgname + "/" + WrtDB::GlobalConfig::GetWidgetSharePath();
+}
+
 std::string WidgetLocation::getTemporaryPackageDir() const
 {
     return m_temp->getTempPath();
index 3d4801c..5698fc0 100644 (file)
@@ -36,7 +36,7 @@
  *
  * /opt/apps/[package_name]
  *           \_____________ /data
- *           \_____________ /data/share
+ *           \_____________ /share
  *           \_____________ /bin
  *           \_____________ /bin/[id_of_installed_package]
  *           \_____________ /res/wgt/
@@ -114,6 +114,7 @@ public:
     std::string getBackupExecFile() const;              // /opt/apps/[package]/backup/bin/[package]
     std::string getUserDataRootDir() const;             // /opt/usr/apps/[package]
     std::string getPrivateStorageDir() const;                 // /opt/usr/apps/[package]/data
+    std::string getShareDir() const;                    // /opt/usr/apps/[package]/share
 
     // Temporary paths
     /**