[Path usage Unification] Plugin Installation part unification
authorKamil Nowac <k.nowac@partner.samsung.com>
Wed, 29 May 2013 13:05:55 +0000 (15:05 +0200)
committerGerrit Code Review <gerrit2@kim11>
Mon, 10 Jun 2013 11:25:57 +0000 (20:25 +0900)
[Issue#] LINUXWRT-395
[Problem] A lot of paths used in wrt are constructed manually
[Cause] N/A
[Solution] Used module DPL::Utils::Path
[Verification] 1. Build wrt-installer repo with --define "WITH_TESTS ON"
2. Install plugins by using wrt-installer -p and
run tests wrt-installer-tests-general --output=text
They shoud install without problems and tests should pass.

Change-Id: I6e03f4732a6bb10df78dfb0bc451f5a3da627ac8

src/jobs/plugin_install/job_plugin_install.cpp
src/jobs/plugin_install/job_plugin_install.h
src/jobs/plugin_install/plugin_install_task.cpp
src/jobs/plugin_install/plugin_installer_context.h
src/jobs/plugin_install/plugin_metafile_reader.h
src/logic/installer_logic.cpp

index 38c0aef..811c049 100644 (file)
@@ -28,7 +28,7 @@
 
 namespace Jobs {
 namespace PluginInstall {
-JobPluginInstall::JobPluginInstall(std::string const &pluginPath,
+JobPluginInstall::JobPluginInstall(DPL::Utils::Path const &pluginPath,
                                    const PluginInstallerStruct &installerStruct)
     :
     Job(PluginInstallation),
index 0af9c04..c4a59ee 100644 (file)
@@ -31,6 +31,7 @@
 #include <job_base.h>
 #include <plugin_install/plugin_installer_struct.h>
 #include <plugin_install/plugin_installer_context.h>
+#include <dpl/utils/path.h>
 
 namespace Jobs {
 namespace PluginInstall {
@@ -47,7 +48,7 @@ class JobPluginInstall :
     /**
      * @brief Automaticaly sets installation process
      */
-    JobPluginInstall(std::string const &pluginPath,
+    JobPluginInstall(DPL::Utils::Path const &pluginPath,
                      const PluginInstallerStruct &installerStruct);
 
     WrtDB::DbPluginHandle getNewPluginHandle() const
@@ -56,7 +57,7 @@ class JobPluginInstall :
     }
     std::string getFilePath() const
     {
-        return m_context.pluginFilePath;
+        return m_context.pluginFilePath.Fullpath();
     }
     bool isReadyToInstall() const
     {
index 65333ba..861dbc2 100644 (file)
@@ -87,16 +87,9 @@ void PluginInstallTask::stepCheckPluginPath()
 {
     LogInfo("Plugin installation: step CheckPluginPath");
 
-    struct stat tmp;
-
-    if (-1 == stat(m_context->pluginFilePath.c_str(), &tmp)) {
+    if(!m_context->pluginFilePath.Exists()){
         ThrowMsg(Exceptions::PluginPathFailed,
-                 "Stat function failed");
-    }
-
-    if (!S_ISDIR(tmp.st_mode)) {
-        ThrowMsg(Exceptions::PluginPathFailed,
-                 "Invalid Directory");
+                 "No such path");
     }
 
     SET_PLUGIN_INSTALL_PROGRESS(PLUGIN_PATH, "Path to plugin verified");
@@ -106,17 +99,15 @@ void PluginInstallTask::stepParseConfigFile()
 {
     LogInfo("Plugin installation: step parse config file");
 
-    struct stat tmp;
-
-    std::string filename = m_context->pluginFilePath + DIRECTORY_SEPARATOR +
-        std::string(GlobalConfig::GetPluginMetafileName());
+    DPL::Utils::Path filename = m_context->pluginFilePath;
+    filename /= GlobalConfig::GetPluginMetafileName();
 
-    if (-1 == stat(filename.c_str(), &tmp)) {
+    if(!filename.Exists()){
         m_dataFromConfigXML = false;
         return;
     }
 
-    LogInfo("Plugin Config file::" << filename);
+    LogInfo("Plugin Config file::" << filename.Filename());
 
     Try
     {
@@ -136,7 +127,7 @@ void PluginInstallTask::stepParseConfigFile()
     }
     Catch(ValidationCore::ParserSchemaException::Base)
     {
-        LogError("Error during file processing " << filename);
+        LogError("Error during file processing " << filename.Filename());
         ThrowMsg(Exceptions::PluginMetafileFailed,
                  "Metafile error");
     }
@@ -148,8 +139,8 @@ void PluginInstallTask::stepFindPluginLibrary()
         return;
     }
     LogDebug("Plugin installation: step find plugin library");
-    std::string pluginPath = m_context->pluginFilePath;
-    size_t indexpos = pluginPath.find_last_of('/');
+    DPL::Utils::Path pluginPath = m_context->pluginFilePath;
+    size_t indexpos = pluginPath.Fullpath().find_last_of('/');
 
     if (std::string::npos == indexpos) {
         indexpos = 0;
@@ -157,7 +148,7 @@ void PluginInstallTask::stepFindPluginLibrary()
         indexpos += 1;  // move after '/'
     }
 
-    std::string libName = pluginPath.substr(indexpos);
+    std::string libName = pluginPath.Fullpath().substr(indexpos);
     libName = GlobalConfig::GetPluginPrefix() + libName +
         GlobalConfig::GetPluginSuffix();
     LogDebug("Plugin .so: " << libName);
@@ -180,16 +171,16 @@ void PluginInstallTask::stepLoadPluginLibrary()
 
     DISABLE_IF_PLUGIN_WITHOUT_LIB()
 
-    std::string filename = m_context->pluginFilePath + DIRECTORY_SEPARATOR +
-        m_pluginInfo.m_libraryName;
+    DPL::Utils::Path filename = m_context->pluginFilePath;
+    filename /= m_pluginInfo.m_libraryName;
 
-    LogDebug("Loading plugin: " << filename);
+    LogDebug("Loading plugin: " << filename.Filename());
 
-    void *dlHandle = dlopen(filename.c_str(), RTLD_LAZY);
+    void *dlHandle = dlopen(filename.Fullpath().c_str(), RTLD_LAZY);
     if (dlHandle == NULL) {
         const char* error = (const char*)dlerror();
         LogError(
-            "Failed to load plugin: " << filename <<
+            "Failed to load plugin: " << filename.Filename() <<
             ". Reason: " << (error != NULL ? error : "unknown"));
         ThrowMsg(Exceptions::PluginLibraryError, "Library error");
     }
@@ -211,7 +202,7 @@ void PluginInstallTask::stepLoadPluginLibrary()
 
     if (rawEntityList == NULL) {
         dlclose(dlHandle);
-        LogError("Failed to read class name" << filename);
+        LogError("Failed to read class name" << filename.Filename());
         ThrowMsg(Exceptions::PluginLibraryError, "Library error");
     }
 
@@ -222,7 +213,7 @@ void PluginInstallTask::stepLoadPluginLibrary()
 
         if (NULL == onWidgetInitProc) {
             dlclose(dlHandle);
-            LogError("Failed to read onWidgetInit symbol" << filename);
+            LogError("Failed to read onWidgetInit symbol" << filename.Filename());
             ThrowMsg(Exceptions::PluginLibraryError, "Library error");
         }
 
@@ -274,7 +265,7 @@ void PluginInstallTask::stepLoadPluginLibrary()
     const js_entity_definition_t *rawEntityListIterator = rawEntityList;
 
     LogInfo("#####");
-    LogInfo("##### Plugin: " << filename << " supports new plugin API");
+    LogInfo("##### Plugin: " << filename.Filename() << " supports new plugin API");
     LogInfo("#####");
 
     while (rawEntityListIterator->parent_name != NULL &&
@@ -308,7 +299,7 @@ void PluginInstallTask::stepRegisterPlugin()
     LogInfo("Plugin installation: step register Plugin");
 
     m_pluginHandle =
-        PluginDAO::registerPlugin(m_pluginInfo, m_context->pluginFilePath);
+        PluginDAO::registerPlugin(m_pluginInfo, m_context->pluginFilePath.Fullpath());
 
     SET_PLUGIN_INSTALL_PROGRESS(REGISTER_PLUGIN, "Plugin registered");
 }
index 026074a..fbf2db5 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <string>
 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+#include <dpl/utils/path.h>
 //#include <plugin_model.h>
 
 using namespace WrtDB;
@@ -50,7 +51,7 @@ struct PluginInstallerContext
         PLUGIN_INSTALL_END
     };
 
-    std::string pluginFilePath;           ///< plugin directory
+    DPL::Utils::Path pluginFilePath;           ///< plugin directory
     WrtDB::DbPluginHandle pluginHandle;
     // if this value is true the plugin model may be created
     // if not plugin installation has failed from some reason
index b0c88f0..6a7734f 100644 (file)
@@ -24,6 +24,7 @@
 #define WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_METAFILE_READER_H_
 
 #include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/utils/path.h>
 #include <vcore/ParserSchema.h>
 
 class PluginMetafileReader
@@ -31,9 +32,9 @@ class PluginMetafileReader
   public:
     PluginMetafileReader();
 
-    void initialize(const std::string &filename)
+    void initialize(const DPL::Utils::Path &filename)
     {
-        m_parserSchema.initialize(filename,
+        m_parserSchema.initialize(filename.Fullpath(),
                                   true,
                                   ValidationCore::SaxReader::VALIDATION_DTD,
                                   std::string());
index fe4f629..6b3f06c 100644 (file)
@@ -118,8 +118,10 @@ Jobs::JobHandle InstallerLogic::InstallPlugin(
 
     LogDebug("New Plugin Installation");
 
-    m_job  =
-        new Jobs::PluginInstall::JobPluginInstall(pluginPath, installerStruct);
+    //Conversion to DPL::Utils::Path is temporary
+    m_job =
+        new Jobs::PluginInstall::JobPluginInstall(DPL::Utils::Path(pluginPath), installerStruct);
+
     // before start install plugin, reset plugin data which is stopped
     // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS)
     ResetProgressPlugins();