[Release] wrt-installer_0.1.47
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_file_manipulation.cpp
index dcb4884..4e25780 100644 (file)
@@ -186,6 +186,12 @@ void TaskFileManipulation::StepCreateDirs()
         LogDebug("Create resource directory");
         WrtUtilMakeDir(widgetBinPath);
         WrtUtilMakeDir(widgetSrcPath);
+        if (m_context.job->getInstallerStruct().m_installMode
+                == InstallMode::INSTALL_MODE_PRELOAD)
+        {
+            std::string userWidgetDir = m_context.locations->getUserDataRootDir();
+            WrtUtilMakeDir(userWidgetDir);
+        }
     }
 
     m_context.job->UpdateProgress(
@@ -237,8 +243,8 @@ void TaskFileManipulation::StepLinkForPreload()
             WrtDB::GlobalConfig::GetWidgetSrcPath();
 
         if (0 != access(srcDir.c_str(), F_OK)) {
-            LogDebug("Make symbolic name for preaload app" << " to " << srcDir <<
-                    "from " << m_context.locations->getSourceDir());
+            LogDebug("Make symbolic name for preaload app" <<
+                    m_context.locations->getSourceDir() << " to " << srcDir);
             std::string resDir = m_context.locations->getUserDataRootDir() +
                 "/res";
 
@@ -258,17 +264,38 @@ void TaskFileManipulation::StepLinkForPreload()
         std::string storagePath = m_context.locations->getPrivateStorageDir();
         std::string dataDir = m_context.locations->getPackageInstallationDir() +
             "/" + WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
+        if (0 != access(dataDir.c_str(), F_OK)) {
+            LogDebug("Make symbolic name for preaload app " <<
+                    storagePath << " to " << dataDir);
+
+            if (symlink(storagePath.c_str(), dataDir.c_str()) != 0)
+            {
+                int error = errno;
+                if (error)
+                    LogPedantic("Failed to make a symbolic name for a file "
+                            << "[" <<  DPL::GetErrnoString(error) << "]");
+                ThrowMsg(Exceptions::FileOperationFailed,
+                        "Symbolic link creating is not done.");
+            }
+            changeOwnerForDirectory(dataDir);
+        }
+
+        if (m_context.widgetConfig.packagingType != PKG_TYPE_HYBRID_WEB_APP) {
+            std::string widgetBinPath = m_context.locations->getBinaryDir();
+            std::string userBinPath = m_context.locations->getUserBinaryDir();
+            LogDebug("Make symbolic link for preload app " << widgetBinPath <<
+                    " to " << userBinPath);
+            if (symlink(widgetBinPath.c_str(), userBinPath.c_str()) != 0)
+            {
+                int error = errno;
+                if (error)
+                    LogPedantic("Failed to make a symbolic name for a file "
+                            << "[" <<  DPL::GetErrnoString(error) << "]");
+                ThrowMsg(Exceptions::FileOperationFailed,
+                        "Symbolic link creating is not done.");
+            }
 
-        if (symlink(storagePath.c_str(), dataDir.c_str()) != 0)
-        {
-            int error = errno;
-            if (error)
-                LogPedantic("Failed to make a symbolic name for a file "
-                        << "[" <<  DPL::GetErrnoString(error) << "]");
-            ThrowMsg(Exceptions::FileOperationFailed,
-                    "Symbolic link creating is not done.");
         }
-        changeOwnerForDirectory(dataDir);
     }
 }
 
@@ -282,6 +309,12 @@ void TaskFileManipulation::StepAbortRenamePath()
             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);
+        }
+
     }
     LogDebug("Rename widget path sucessful!");
 }