[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_file_manipulation.cpp
index b1629de..c7b0ec6 100644 (file)
@@ -43,7 +43,7 @@
 
 namespace {
 const mode_t PRIVATE_STORAGE_MODE = 0700;
-const mode_t SHARE_MODE = 0705;
+const mode_t SHARED_STORAGE_MODE = 0755;
 }
 
 using namespace WrtDB;
@@ -99,12 +99,12 @@ bool _FolderCopy(std::string source, std::string dest)
     return true;
 }
 
-void changeOwnerForDirectory(std::string storagePath) {
+void changeOwnerForDirectory(std::string storagePath, mode_t mode) {
     if (euidaccess(storagePath.c_str(), F_OK) != 0) {
-        if (!WrtUtilMakeDir(storagePath, PRIVATE_STORAGE_MODE)) {
-            LogError("Failed to create directory for private storage");
+        if (!WrtUtilMakeDir(storagePath, mode)) {
+            LogError("Failed to create directory : " << storagePath);
             ThrowMsg(Jobs::WidgetInstall::Exceptions::FileOperationFailed,
-                     "Failed to create directory for private storage");
+                     "Failed to create directory : " << storagePath);
         }
         // '5000' is default uid, gid for applications.
         // So installed applications should be launched as process of uid
@@ -118,7 +118,7 @@ void changeOwnerForDirectory(std::string storagePath) {
                      "Chown to invaild user");
         }
     } else if (euidaccess(storagePath.c_str(), W_OK | R_OK | X_OK) == 0) {
-        LogInfo("Private storage already exists.");
+        LogDebug(storagePath << " already exists.");
         // Even if private directory already is created, private dircetory
         // should change owner.
         if (chown(storagePath.c_str(),
@@ -128,7 +128,7 @@ void changeOwnerForDirectory(std::string storagePath) {
             ThrowMsg(Jobs::WidgetInstall::Exceptions::FileOperationFailed,
                      "Chown to invaild user");
         }
-        if (chmod(storagePath.c_str(), PRIVATE_STORAGE_MODE) != 0) {
+        if (chmod(storagePath.c_str(), mode) != 0) {
             ThrowMsg(Jobs::WidgetInstall::Exceptions::FileOperationFailed,
                      "chmod to 0700");
         }
@@ -146,12 +146,12 @@ TaskFileManipulation::TaskFileManipulation(InstallerContext& context) :
     m_context(context),
     m_extHandle(NULL)
 {
+    AddStep(&TaskFileManipulation::StartStep);
     if (INSTALL_LOCATION_TYPE_EXTERNAL !=
             m_context.locationType)
     {
         AddStep(&TaskFileManipulation::StepCreateDirs);
-        if (m_context.widgetConfig.packagingType !=
-            WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+        if (m_context.mode.extension != InstallMode::ExtensionType::DIR)
         {
             AddStep(&TaskFileManipulation::StepRenamePath);
             AddAbortStep(&TaskFileManipulation::StepAbortRenamePath);
@@ -168,6 +168,7 @@ TaskFileManipulation::TaskFileManipulation(InstallerContext& context) :
 
         AddAbortStep(&TaskFileManipulation::StepAbortCreateExternalDir);
     }
+    AddStep(&TaskFileManipulation::EndStep);
 }
 
 void TaskFileManipulation::StepCreateDirs()
@@ -206,17 +207,21 @@ void TaskFileManipulation::StepCreatePrivateStorageDir()
     LogDebug("Create private storage directory : " <<
             m_context.locations->getPrivateStorageDir());
 
+    changeOwnerForDirectory(storagePath, PRIVATE_STORAGE_MODE);
+
     if (m_context.isUpdateMode) { //update
         std::string backData = m_context.locations->getBackupPrivateDir();
         LogDebug("copy private storage " << backData << " to " << storagePath);
-        WrtUtilMakeDir(storagePath);
         if (!DirectoryApi::DirectoryCopy(backData, storagePath)) {
             LogError("Failed to rename " << backData << " to " << storagePath);
             ThrowMsg(Exceptions::BackupFailed,
                     "Error occurs copy private strage files");
         }
     }
-    changeOwnerForDirectory(storagePath);
+
+    std::string tempStoragePath = m_context.locations->getPrivateTempStorageDir();
+    LogDebug("Create temp private storage directory : " << tempStoragePath);
+    changeOwnerForDirectory(tempStoragePath, PRIVATE_STORAGE_MODE);
 }
 
 void TaskFileManipulation::StepRenamePath()
@@ -249,17 +254,16 @@ void TaskFileManipulation::StepRenamePath()
 void TaskFileManipulation::StepLinkForPreload()
 {
     if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
-        std::string srcDir = m_context.locations->getUserDataRootDir() +
-            WrtDB::GlobalConfig::GetWidgetSrcPath();
+        std::string optRes = m_context.locations->getUserDataRootDir() +
+            WrtDB::GlobalConfig::GetWidgetResPath();
+        std::string usrRes = m_context.locations->getPackageInstallationDir() +
+            WrtDB::GlobalConfig::GetWidgetResPath();
 
-        if (0 != access(srcDir.c_str(), F_OK)) {
+        if (0 != access(optRes.c_str(), F_OK)) {
             LogDebug("Make symbolic name for preaload app" <<
-                    m_context.locations->getSourceDir() << " to " << srcDir);
-            std::string resDir = m_context.locations->getUserDataRootDir() +
-                "/res";
+                    usrRes << " to " << optRes);
 
-            WrtUtilMakeDir(resDir);
-            if (symlink(m_context.locations->getSourceDir().c_str(), srcDir.c_str()) != 0)
+            if (symlink(usrRes.c_str(), optRes.c_str()) != 0)
             {
                 int error = errno;
                 if (error)
@@ -287,7 +291,7 @@ void TaskFileManipulation::StepLinkForPreload()
                 ThrowMsg(Exceptions::FileOperationFailed,
                         "Symbolic link creating is not done.");
             }
-            changeOwnerForDirectory(dataDir);
+            changeOwnerForDirectory(dataDir, PRIVATE_STORAGE_MODE);
         }
 
         if (m_context.widgetConfig.packagingType != PKG_TYPE_HYBRID_WEB_APP) {
@@ -313,19 +317,18 @@ void TaskFileManipulation::StepAbortRenamePath()
 {
     LogDebug("[Rename Widget Path] Aborting.... (Rename path)");
     std::string widgetPath;
-    if (m_context.widgetConfig.packagingType != PKG_TYPE_HYBRID_WEB_APP) {
-        widgetPath = m_context.locations->getPackageInstallationDir();
-        if (!WrtUtilRemove(widgetPath)) {
-            ThrowMsg(Exceptions::RemovingFolderFailure,
-                     "Error occurs during removing existing folder");
-        }
-        // Remove user data directory if preload web app.
-        std::string userData = m_context.locations->getUserDataRootDir();
-        if (0 == access(userData.c_str(), F_OK)) {
-            WrtUtilRemove(userData);
+    widgetPath = m_context.locations->getPackageInstallationDir();
+    if (!WrtUtilRemove(widgetPath)) {
+        LogError("Error occurs during removing existing folder");
+    }
+    // Remove user data directory if preload web app.
+    std::string userData = m_context.locations->getUserDataRootDir();
+    if (0 == access(userData.c_str(), F_OK)) {
+        if (!WrtUtilRemove(userData)) {
+            LogError("Error occurs during removing user data directory");
         }
-
     }
+
     LogDebug("Rename widget path sucessful!");
 }
 
@@ -428,9 +431,21 @@ void TaskFileManipulation::StepCreateSharedFolder()
         }
     } else {
         WrtUtilMakeDir(m_context.locations->getSharedResourceDir());
-        WrtUtilMakeDir(m_context.locations->getSharedDataDir());
-        WrtUtilMakeDir(m_context.locations->getSharedTrustedDir());
+        changeOwnerForDirectory(m_context.locations->getSharedDataDir(),
+                SHARED_STORAGE_MODE);
+        changeOwnerForDirectory(m_context.locations->getSharedTrustedDir(),
+                SHARED_STORAGE_MODE);
     }
 }
+
+void TaskFileManipulation::StartStep()
+{
+    LogDebug("--------- <TaskFileManipulation> : START ----------");
+}
+
+void TaskFileManipulation::EndStep()
+{
+    LogDebug("--------- <TaskFileManipulation> : END ----------");
+}
 } //namespace WidgetInstall
 } //namespace Jobs