save installed path to db for preload widget
authorSoyoung Kim <sy037.kim@samsung.com>
Wed, 14 Nov 2012 05:11:29 +0000 (14:11 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Fri, 30 Nov 2012 11:36:56 +0000 (20:36 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] Add logic to save installed path for preload widget
[SCMRequest] this commit should be released with wrt-commmons

Change-Id: I51942b53109fad02e8abd1f47436fa225a025117

17 files changed:
etc/wrt_preinstall_widgets.sh
src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/job_widget_install.h
src/jobs/widget_install/task_commons.cpp
src/jobs/widget_install/task_commons.h
src/jobs/widget_install/task_file_manipulation.cpp
src/jobs/widget_install/task_private_storage.cpp
src/jobs/widget_install/task_widget_config.cpp
src/jobs/widget_install/task_widget_config.h
src/jobs/widget_install/widget_installer_struct.h
src/jobs/widget_uninstall/task_remove_files.cpp
src/misc/widget_location.cpp
src/misc/widget_location.h
src/wrt-installer/wrt_installer.cpp
src/wrt-installer/wrt_installer.h
src/wrt-installer/wrt_installer_api.cpp
src/wrt-installer/wrt_installer_api.h

index 5b36b0c..9742d0d 100755 (executable)
@@ -23,7 +23,7 @@ install_widgets() {
        for list in $_wgt_list
        do
                echo "Install $list"
-               return_string=`wrt-installer -i $list`
+               return_string=`wrt-installer -il $list`
         if [ "$return_string" != "${return_string/installed/}" ]; then
             echo "$list widget installation success"
             rm -rf $list
index 96aa5bb..ef7fbe4 100644 (file)
@@ -128,6 +128,22 @@ bool hasExtension(const std::string& filename, const std::string& extension) {
     }
     return (0 == filename.compare(fileLen-extLen, extLen, extension));
 }
+
+bool checkTizenIdExist(const std::string& tizenId) {
+    std::string installPath =
+        std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
+        "/" + tizenId;
+    std::string preinstallPath =
+        std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
+        "/" + tizenId;
+
+    struct stat dirStat;
+    if ((stat(installPath.c_str(), &dirStat) == 0) &&
+            (stat(preinstallPath.c_str(), &dirStat) == 0)) {
+        return true;
+    }
+    return false;
+}
 } // namespace anonymous
 
 namespace Jobs {
@@ -256,7 +272,8 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
 
     Try
     {
-        std::string tempDir = Jobs::WidgetInstall::createTempPath();
+        std::string tempDir =
+            Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
 
         m_isDRM = isDRMWidget(widgetPath);
         if (true == m_isDRM) {
@@ -291,7 +308,8 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
 }
 
 bool JobWidgetInstall::setTizenId(
-        const WrtDB::ConfigParserData &configInfo, ConfigureResult result)
+        const WrtDB::ConfigParserData &configInfo, ConfigureResult result,
+        bool preload)
 {
     regex_t reg;
     if(regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
@@ -299,13 +317,13 @@ bool JobWidgetInstall::setTizenId(
     }
 
     struct stat dirStat;
+
     if(!!configInfo.tizenId) {
         LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId);
         if ((regexec(&reg, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
              static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
-            ((stat((std::string(GlobalConfig::GetUserInstalledWidgetPath()) + "/"
-                   + DPL::ToUTF8String(*(configInfo.tizenId))).c_str(), &dirStat) == 0)
-             && result != ConfigureResult::Updated))
+            (checkTizenIdExist(DPL::ToUTF8String(*(configInfo.tizenId))) &&
+             result != ConfigureResult::Updated))
         {
             //it is true when tizenId does not fit REG_TIZENID_PATTERN
             LogError("tizen_id provided but not proper.");
@@ -320,19 +338,12 @@ bool JobWidgetInstall::setTizenId(
         // only for installation, not for update
         if (result == ConfigureResult::Ok) {
             //check if there is package with same name and if generate different name
-            std::string path = GlobalConfig::GetUserInstalledWidgetPath();
-            path += "/";
-
-            std::ostringstream newPath;
-            newPath << path << tizenId;
 
             LogDebug("Checking if tizen id is unique");
             while (true) {
-                if (stat(newPath.str().c_str(), &dirStat) == 0) {
+                if (checkTizenIdExist(DPL::ToUTF8String(tizenId))) {
                     //path exist, chose another one
                     tizenId = WidgetDAOReadOnly::generateTizenId();
-                    newPath.str("");
-                    newPath << path << tizenId;
                     continue;
                 }
                 break;
@@ -355,7 +366,8 @@ void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
     m_installerContext.locations =
         WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
                 widgetPath, tempPath,
-                m_installerContext.widgetConfig.packagingType);
+                m_installerContext.widgetConfig.packagingType,
+                m_jobStruct.m_preload);
 
     LogInfo("widgetSource " << widgetPath);
 }
@@ -437,7 +449,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
             return ConfigureResult::Failed;
     }
 
-    if (!setTizenId(configData, ret)) {
+    if (!setTizenId(configData, ret, m_jobStruct.m_preload)) {
         return ConfigureResult::Failed;
     } else {
         using namespace PackageManager;
index 29ea4b2..ad8dedb 100644 (file)
@@ -72,7 +72,8 @@ class JobWidgetInstall :
             const OptionalWidgetVersion &existingVersion,
             const OptionalWidgetVersion &incomingVersion) const;
     bool setTizenId(const WrtDB::ConfigParserData &configInfo,
-                    ConfigureResult result);
+                    ConfigureResult result,
+                    bool preload);
     void displayWidgetInfo();
     void configureWidgetLocation(const std::string & widgetPath,
                                  const std::string &tempPath);
index 10c73e8..abf6623 100644 (file)
@@ -43,14 +43,20 @@ const mode_t TEMPORARY_PATH_MODE = 0775;
 } // namespace
 
 
-std::string createTempPath()
+std::string createTempPath(bool preload)
 {
     LogInfo("Step: Creating temporary path");
 
    // Temporary path
    std::ostringstream tempPathBuilder;
 
-   tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+   //tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+   if (preload) {
+       tempPathBuilder << WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
+   } else {
+       tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+   }
+   tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
    tempPathBuilder << "/";
    tempPathBuilder << TEMPORARY_PATH_POSTFIX;
    tempPathBuilder << "_";
index dbb41eb..5193c3d 100644 (file)
@@ -29,7 +29,8 @@ namespace WidgetInstall {
 
 //TODO make directory like jobs common?
 
-std::string createTempPath();
+std::string createTempPath(bool preload = false);
+std::string createTempPath(bool preload);
 
 void createTempPath(const std::string& path);
 
index 759510e..2bd896b 100644 (file)
@@ -59,6 +59,11 @@ void TaskFileManipulation::StepCreateDirs()
 
     WrtUtilMakeDir(widgetPath);
 
+    if (m_context.job->getInstallerStruct().m_preload) {
+        std::string privateDir = m_context.locations->getBasePrivateDir();
+        WrtUtilMakeDir(privateDir);
+    }
+
     // If package type is widget with osp service, we don't need to make bin
     // and src directory
     if (m_context.widgetConfig.packagingType == PKG_TYPE_HYBRID_WEB_APP) {
index 8d9934f..853db0a 100644 (file)
@@ -63,20 +63,20 @@ void TaskPrivateStorage::StepCreateDirectory()
     m_context.installStep =
         InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE;
 
-    std::ostringstream widgetPath;
+    std::ostringstream widgetDataPath;
     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
     if(!pkgname.IsNull()) {
-        widgetPath << m_context.locations->getPackageInstallationDir() << "/";
+        widgetDataPath << m_context.locations->getBasePrivateDir() << "/";
     } else {
         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
     }
 
-    if (euidaccess(widgetPath.str().c_str(), W_OK | X_OK) != 0) {
+    if (euidaccess(widgetDataPath.str().c_str(), W_OK | X_OK) != 0) {
         ThrowMsg(Exceptions::InternalError, DPL::GetErrnoString());
     }
 
     std::ostringstream storagePath;
-    storagePath << widgetPath.str().c_str()
+    storagePath << widgetDataPath.str().c_str()
                 << GlobalConfig::GetWidgetPrivateStoragePath();
 
     if (euidaccess(storagePath.str().c_str(), F_OK) != 0) {
index 1d7f093..2b51238 100644 (file)
@@ -80,6 +80,7 @@ TaskWidgetConfig::TaskWidgetConfig(InstallerContext& installContext) :
     AddStep(&TaskWidgetConfig::ProcessLocalizedStartFiles);
     AddStep(&TaskWidgetConfig::ProcessBackgroundPageFile);
     AddStep(&TaskWidgetConfig::ProcessLocalizedIcons);
+    AddStep(&TaskWidgetConfig::ProcessWidgetInstalledPath);
     AddStep(&TaskWidgetConfig::StepVerifyFeatures);
     AddStep(&TaskWidgetConfig::StepCheckMinVersionInfo);
 
@@ -363,6 +364,13 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
     }
 }
 
+void TaskWidgetConfig::ProcessWidgetInstalledPath()
+{
+    LogDebug("ProcessWidgetInstalledPath");
+    m_installContext.widgetConfig.widgetInstalledPath =
+        DPL::FromUTF8String(m_installContext.locations->getPackageInstallationDir());
+}
+
 void TaskWidgetConfig::StepCancelWidgetInstallationAfterVerifyFeatures()
 {
     LogDebug("StepCancelWidgetInstallationAfterVerifyFeatures");
index 740af5f..2b0b7dc 100755 (executable)
@@ -78,6 +78,7 @@ class TaskWidgetConfig :
     void ProcessBackgroundPageFile();
     void ProcessLocalizedIcons();
     void ProcessIcon(const WrtDB::ConfigParserData::Icon& icon);
+    void ProcessWidgetInstalledPath();
     void StepVerifyFeatures();
     void StepShowWidgetInfo();
     void StepCheckMinVersionInfo();
index 108fd66..716bb56 100755 (executable)
@@ -101,10 +101,12 @@ struct WidgetInstallationStruct : public WidgetInstallCallbackBase
 {
     WidgetUpdateMode::Type updateMode;
     bool m_quiet;
+    bool m_preload;
 
     // It must be empty-constructible as a parameter of generic event
     WidgetInstallationStruct() : updateMode(WidgetUpdateMode::Zero),
-                                m_quiet(true)
+                                m_quiet(true),
+                                m_preload(false)
     {
     }
 
@@ -112,10 +114,12 @@ struct WidgetInstallationStruct : public WidgetInstallCallbackBase
             InstallerProgressCallback progress,
             void *param,
             WidgetUpdateMode::Type mode,
-            bool quiet) :
+            bool quiet,
+            bool preload) :
         WidgetInstallCallbackBase(finished, progress, param),
         updateMode(mode),
-        m_quiet(quiet)
+        m_quiet(quiet),
+        m_preload(preload)
     {
     }
 };
index 7a8f66b..d258d0c 100644 (file)
@@ -62,6 +62,10 @@ void TaskRemoveFiles::StepRemoveInstallationDirectory()
     if(!WrtUtilRemove(widgetDir)){
         LogWarning("Removing widget installation directory failed");
     }
+    std::string dataDir = m_context.locations->getBasePrivateDir();
+    if(!WrtUtilRemove(dataDir)){
+        LogWarning(dataDir + " is already removed");
+    }
     m_context.job->UpdateProgress(
         UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
         "Widget INstallation Directory Removal Finished");
@@ -142,7 +146,7 @@ void TaskRemoveFiles::StepRemoveExternalLocations()
             LogDebug("  -> " << *path);
             int ret = remove(path->c_str());
             if (ret != 0) {
-                LogDebug("Failed to remove the file: " << path->c_str() << " with error: " << strerror(errno));
+                LogError("Failed to remove the file: " << path->c_str() << " with error: " << strerror(errno));
             }
         }
         else if(WrtUtilDirExists(*path))
index 64345e0..3686afc 100644 (file)
@@ -43,7 +43,7 @@ WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
 {
     LogDebug("Removing widget installation temporary directory: " << m_dirpath.c_str());
     if(!WrtUtilRemove(m_dirpath)){
-        LogDebug("Fail at removing directory: " << m_dirpath.c_str());
+        LogError("Fail at removing directory: " << m_dirpath.c_str());
     }
 }
 
@@ -67,47 +67,58 @@ WidgetLocation::~WidgetLocation()
 
 WidgetLocation::WidgetLocation(const std::string & widgetname,
                                std::string sourcePath,
-                               WrtDB::PackagingType t):
+                               WrtDB::PackagingType t,
+                               bool preload):
                                     m_pkgname(widgetname),
                                     m_widgetSource(sourcePath),
                                     m_type(t),
                                     m_temp(new WidgetLocation::DirectoryDeletor())
 {
+    if (preload) {
+        m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+    } else {
+        m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
+    }
 }
 
 WidgetLocation::WidgetLocation(const std::string & widgetname,
                                std::string sourcePath,
                                std::string dirPath,
-                               WrtDB::PackagingType t):
+                               WrtDB::PackagingType t,
+                               bool preload):
                                     m_pkgname(widgetname),
                                     m_widgetSource(sourcePath),
                                     m_type(t),
                                     m_temp(new
                                             WidgetLocation::DirectoryDeletor(dirPath))
 {
+    if (preload) {
+        m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
+    } else {
+        m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+    }
 }
 
 // TODO cache all these paths
 std::string WidgetLocation::getInstallationDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
+    return m_installedPath;
 }
 
 std::string WidgetLocation::getPackageInstallationDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
-            + m_pkgname;
+    return m_installedPath + "/" + m_pkgname;
 }
 
 std::string WidgetLocation::getSourceDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+    return m_installedPath + "/"
             + m_pkgname + WrtDB::GlobalConfig::GetWidgetSrcPath();
 }
 
 std::string WidgetLocation::getBinaryDir() const
 {
-    return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+    return m_installedPath + "/"
             + m_pkgname + WrtDB::GlobalConfig::GetUserWidgetExecPath();
 }
 
@@ -199,6 +210,12 @@ void WidgetLocation::registerExternalLocation(const std::string & file)
     m_externals.push_back(file);
 }
 
+std::string WidgetLocation::getBasePrivateDir() const
+{
+    return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
+        "/" + m_pkgname;
+}
+
 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const
 {
     return m_externals;
index ab9fa29..64408f9 100644 (file)
@@ -91,15 +91,18 @@ public:
      * In destruction removes temporary directory
      */
     WidgetLocation(const std::string & widgetname, std::string sourcePath,
-                   WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP);
+                   WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
+                   bool preload = false);
 
     WidgetLocation(const std::string & widgetname, std::string sourcePath,
                    std::string dirPath,
-                   WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP);
+                   WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
+                   bool preload = false);
+
     ~WidgetLocation();
 
     // Installed paths
-    std::string getInstallationDir() const;              // /opt/apps
+    std::string getInstallationDir() const;              // /opt/apps or /usr/apps
     std::string getPackageInstallationDir() const;       // /opt/apps/[package]
     std::string getSourceDir() const;                    // /opt/apps/[package]/res/wgt
     std::string getBinaryDir() const;                    // /opt/apps/[package]/bin
@@ -108,6 +111,7 @@ public:
     std::string getBackupSourceDir() const;              // /opt/apps/[package]/backup/res/wgt
     std::string getBackupBinaryDir() const;              // /opt/apps/[package]/backup/bin
     std::string getBackupExecFile() const;              // /opt/apps/[package]/backup/bin/[package]
+    std::string getBasePrivateDir() const;                  // /opt/apps
 
     // Temporary paths
     /**
@@ -185,6 +189,7 @@ private:
     WrtDB::PackagingType m_type;
     std::shared_ptr<DirectoryDeletor> m_temp;      //directory
     WrtDB::ExternalLocationList m_externals;
+    std::string m_installedPath;
 };
 
 #endif // WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
index 38db876..fd6f903 100644 (file)
@@ -89,7 +89,8 @@ WrtInstaller::WrtInstaller(int argc, char **argv) :
     m_installByPkgmgr(false),
     m_quiet(true),
     m_popup(NULL),
-    m_startupPluginInstallation(false)
+    m_startupPluginInstallation(false),
+    m_preloadWidget(false)
 {
     Touch();
     LogDebug("App Created");
@@ -167,6 +168,15 @@ void WrtInstaller::OnCreate()
             m_packagePath = m_argv[2];
             m_installPolicy = WRT_WIM_POLICY_FORCE_INSTALL;
             AddStep(&WrtInstaller::installStep);
+        } else if (arg == "-il" || arg == "--install-preload") {
+            if (m_argc != 3) {
+                return showHelpAndQuit();
+            }
+
+            m_packagePath = m_argv[2];
+            m_preloadWidget = true;
+            m_installPolicy = WRT_WIM_POLICY_WAC;
+            AddStep(&WrtInstaller::installStep);
         } else if (arg == "-un" || arg == "--uninstall-name") {
             if (m_argc != 3) {
                 return showHelpAndQuit();
@@ -333,7 +343,8 @@ void WrtInstaller::installStep()
                        (!m_quiet || m_installByPkgmgr)
                        ? &staticWrtInstallProgressCallback : NULL,
                        m_installPolicy,
-                       m_quiet);
+                       m_quiet,
+                       m_preloadWidget);
 }
 
 void WrtInstaller::installPluginsStep()
index d6e2315..3152f0e 100644 (file)
@@ -149,6 +149,7 @@ class WrtInstaller :
     bool m_startupPluginInstallation;
     std::string m_webAppConfig;
     std::string m_webAppIcon;
+    bool m_preloadWidget;
 
     typedef std::list<std::string> PluginPathList;
     DPL::Optional<PluginPathList> m_pluginsPaths;
index 95d59ab..651a020 100755 (executable)
@@ -144,6 +144,13 @@ extern "C"
                 "Path <" << GlobalConfig::GetUserInstalledWidgetPath() <<
                 "> does not exist.");
         }
+
+        if_ok &= (checkPath(GlobalConfig::GetUserPreloadedWidgetPath()));
+        if (!if_ok) {
+            LogError(
+                "Path <" << GlobalConfig::GetUserPreloadedWidgetPath() <<
+                "> does not exist.");
+        }
         return if_ok;
     }
 
@@ -316,7 +323,8 @@ extern "C"
                                        WrtInstallerStatusCallback status_cb,
                                        WrtProgressCallback progress_cb,
                                        wrt_widget_update_mode_t update_mode,
-                                       bool quiet)
+                                       bool quiet,
+                                       bool preload)
     {
         UNHANDLED_EXCEPTION_HANDLER_BEGIN
         {
@@ -331,7 +339,8 @@ extern "C"
                         new InstallerCallbacksTranslate::StatusCallbackStruct(
                             userdata, status_cb, progress_cb),
                         translateWidgetUpdateMode(update_mode),
-                        quiet)));
+                        quiet,
+                        preload)));
         }
         UNHANDLED_EXCEPTION_HANDLER_END
     }
index 8d77308..6b091c9 100755 (executable)
@@ -199,7 +199,9 @@ void wrt_installer_shutdown(void);
  *                      void *user_parameter,
  *                      WrtInstallerStatusCallback status_callback,
  *                      WrtProgressCallback progress_callback,
- *                      wrt_widget_update_mode_t update_mode);
+ *                      wrt_widget_update_mode_t update_mode,
+ *                      bool quiet,
+ *                      bool preload);
  *
  * @brief Installs widget from given path
  *
@@ -216,6 +218,8 @@ void wrt_installer_shutdown(void);
  *                                  If you don't want to get progress data, this
  *                                  should be NULL
  * @param [in]  install_mode        Installation mode
+ * @param [in]  quiet               quiet mode
+ * @param [in]  preload             preload widget install
  * @return                          Nothing (status returned in callback).
  *
  * Sample code:
@@ -224,7 +228,9 @@ void wrt_installer_shutdown(void);
  *                      NULL,
  *                      install_cb,
  *                      progress_cb,
- *                      WRT_WIM_POLICY_WAC);
+ *                      WRT_WIM_POLICY_WAC,
+ *                      false,
+ *                      false);
  * @endcode
  *
  * @see wrt_installer_uninstall_widget
@@ -234,7 +240,8 @@ void wrt_install_widget(const char *path,
         WrtInstallerStatusCallback status_callback,
         WrtProgressCallback progress_callback,
         wrt_widget_update_mode_t update_mode,
-        bool quiet);
+        bool quiet,
+        bool preload);
 
 /**
  * @fn void wrt_installer_uninstall_widget (const char * const pkg_name,