Change data type for two attributes of <tizen:box-content> on xsd schema
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_plugins_copy.cpp
index c91f7c2..f5cad57 100644 (file)
@@ -26,6 +26,7 @@
 #include <dpl/string.h>
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/errno_string.h>
+#include <widget_install/job_widget_install.h>
 #include <widget_install_context.h>
 #include <widget_install/widget_install_errors.h>
 #include <dpl/exception.h>
@@ -84,19 +85,25 @@ void TaskPluginsCopy::StepFindPlugins()
 
     /* Find all .so files and store their names in list */
     DIR *dir;
-    struct dirent *entry;
     struct stat st;
     LogDebug("Opening plugins directory");
     dir = opendir(m_npsource.c_str());
     if (dir == NULL) {
         LogError("Unable to open plugins directory");
-        ThrowMsg(Exceptions::InternalError, "Unable to read plugins directory");
+        ThrowMsg(Exceptions::FileOperationFailed, "Unable to read plugins directory");
     }
     std::string tempname;
+    struct dirent entry;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
     const std::string ext(".so");
     /* Listing directory and checking entries found inside */
-    while ((entry = readdir(dir)) != NULL) {
-        tempname = m_npsource + "/" + entry->d_name;
+    for (return_code = readdir_r(dir, &entry, &result);
+                result != NULL && return_code == 0;
+                return_code = readdir_r(dir, &entry, &result))
+    {
+        tempname = m_npsource + "/" + entry.d_name;
         if (lstat(tempname.c_str(), &st) != 0) {
             LogWarning(
                 "Failed to call \"lstat\" (errno:" << errno
@@ -106,11 +113,11 @@ void TaskPluginsCopy::StepFindPlugins()
         }
         /* Directories other than "." and ".." should not be found*/
         if (S_ISDIR(st.st_mode)) {
-            if (strncmp(entry->d_name, "..", 2) != 0
-                && strncmp(entry->d_name, ".", 1) != 0)
+            if (strncmp(entry.d_name, "..", 2) != 0
+                && strncmp(entry.d_name, ".", 1) != 0)
             {
                 LogError("Directory detected instead of plugin file: "
-                         << entry->d_name);
+                         << entry.d_name);
                 /* Subdirectories inside plugins/ARCH are not supported */
                 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
                     LogError(
@@ -126,7 +133,7 @@ void TaskPluginsCopy::StepFindPlugins()
             }
         }
 
-        tempname = std::string(entry->d_name);
+        tempname = std::string(entry.d_name);
         /* Check whether file extension is ".so" */
         if (tempname.compare(tempname.size() - ext.size(), ext.size(),
                              ext) == 0)
@@ -139,6 +146,10 @@ void TaskPluginsCopy::StepFindPlugins()
             LogWarning("Non-plugin file found: " << tempname);
         }
     }
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
+    }
+    errno = 0;
     if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
         LogError("Failed to close dir: " << m_npsource << " with error: "
                                          << DPL::GetErrnoString());
@@ -162,7 +173,7 @@ void TaskPluginsCopy::StepCopyPlugins()
     LogDebug("Creating destination plugin directory");
     if (!WrtUtilMakeDir(m_npdestination, InstallationPluginsDirMode)) {
         LogError("Failed to create directory for plugins");
-        ThrowMsg(Exceptions::InternalError,
+        ThrowMsg(Exceptions::FileOperationFailed,
                  "Failed to create directory for plugins");
     }
 
@@ -170,7 +181,7 @@ void TaskPluginsCopy::StepCopyPlugins()
     /* Copy plugins from widget package into
      * .netscape/plugins in widget's target directory */
     for (std::list<std::string>::const_iterator it = m_nplugins.begin();
-         it != m_nplugins.end(); it++)
+         it != m_nplugins.end(); ++it)
     {
         LogDebug("Copying plugin file: " << (*it));
         source = m_npsource + "/" + (*it);
@@ -178,7 +189,7 @@ void TaskPluginsCopy::StepCopyPlugins()
         if (rename(source.c_str(), destination.c_str()) != 0) {
             LogError("Failed to move " << source << " to " << destination);
             LogError("(errno: " << errno << ")");
-            ThrowMsg(Exceptions::InternalError, "Failed to copy plugin file");
+            ThrowMsg(Exceptions::FileOperationFailed, "Failed to copy plugin file");
         }
     }
 
@@ -191,10 +202,14 @@ void TaskPluginsCopy::StepCopyPlugins()
      * architectures). */
     if (!WrtUtilRemove(source)) {
         LogError("Failed to plugins source remove directory");
-        ThrowMsg(Exceptions::InternalError,
+        ThrowMsg(Exceptions::FileOperationFailed,
                  "Failed to plugins source remove directory");
     }
     LogDebug("Plugins copying step ended");
+
+    m_context.job->UpdateProgress(
+            InstallerContext::INSTALL_PLUGINS_COPY,
+            "Plugins copy");
 }
 
 void TaskPluginsCopy::StepCopyingFinished()