* @brief Copying plugins delivered in widget package.
*/
+#include <unistd.h>
#include "task_plugins_copy.h"
#include <dpl/log/log.h>
#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>
#endif
namespace {
- const std::string PackagePluginsDir = "/plugins/";
- const std::string InstallationPluginsDir = "/data/.netscape/plugins/";
- const mode_t InstallationPluginsDirMode = 0755;
+const std::string PackagePluginsDir = "/plugins/";
+const std::string InstallationPluginsDir = "/data/.netscape/plugins/";
+const mode_t InstallationPluginsDirMode = 0755;
}
namespace Jobs {
namespace WidgetInstall {
-
TaskPluginsCopy::TaskPluginsCopy(InstallerContext& context) :
DPL::TaskDecl<TaskPluginsCopy>(this),
m_context(context)
AddStep(&TaskPluginsCopy::StepCopyingFinished);
LogDebug("Widget plugins copy task ended");
m_npsource = m_context.locations->getSourceDir() + PackagePluginsDir
- + plugins_dir;
+ + plugins_dir;
m_npdestination = m_context.locations->getPackageInstallationDir()
- + InstallationPluginsDir;
+ + InstallationPluginsDir;
}
void TaskPluginsCopy::StepFindPlugins()
LogDebug("Starting plugins finding step");
/* Check whether plugins directory for actual architecture exists
* (plugins for other architectures are omitted even they exists). */
- if(!WrtUtilDirExists(m_npsource)) {
- LogDebug("Plugins directory (" <<m_npsource
- <<") does not exists - skipping copy step");
+ if (!WrtUtilDirExists(m_npsource)) {
+ LogDebug(
+ "Plugins directory (" << m_npsource
+ <<
+ ") does not exists - skipping copy step");
SwitchToStep(&TaskPluginsCopy::StepCopyingFinished);
return;
}
/* 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) {
+ 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;
- if(lstat(tempname.c_str(), &st) != 0) {
- LogDebug("Failed to call \"lstat\" (errno:" <<errno
- <<") on entry - skipping");
+ 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
+ <<
+ ") on entry - skipping");
continue;
}
/* 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 (S_ISDIR(st.st_mode)) {
+ 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("Failed to close dir: " << m_npsource
- << " with error: " << DPL::GetErrnoString());
+ LogError(
+ "Failed to close dir: " << m_npsource
+ << " with error: " <<
+ DPL::GetErrnoString());
}
- ThrowMsg(Exceptions::PluginsSubdirectory,
- "Subdirectories inside plugins directory are not supported");
- }
- else {
+ ThrowMsg(
+ Exceptions::PluginsSubdirectory,
+ "Subdirectories inside plugins directory are not supported");
+ } else {
continue;
}
}
- 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) {
+ if (tempname.compare(tempname.size() - ext.size(), ext.size(),
+ ext) == 0)
+ {
/* Plugin file found */
- LogDebug("Plugin file found: " <<tempname);
+ LogDebug("Plugin file found: " << tempname);
m_nplugins.push_back(tempname);
- }
- else {
+ } else {
/* Non-.so file found in plugins directory- skipping */
- LogWarning("Non-plugin file found: " <<tempname);
+ 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());
+ << DPL::GetErrnoString());
}
/* If no .so files found (list is empty) abort taks*/
- if(m_nplugins.empty()) {
+ if (m_nplugins.empty()) {
LogError("No valid plugin files found");
ThrowMsg(Exceptions::EmptyPluginsDirectory, "No valid plugin found");
}
- LogDebug("Number of detected plugins: " <<m_nplugins.size());
+ LogDebug("Number of detected plugins: " << m_nplugins.size());
LogDebug("Plugins finding step ended");
}
/* Create new directory for plugins (data/.netscape/plugins/) */
LogDebug("Creating destination plugin directory");
- if(!WrtUtilMakeDir(m_npdestination, InstallationPluginsDirMode)){
+ if (!WrtUtilMakeDir(m_npdestination, InstallationPluginsDirMode)) {
LogError("Failed to create directory for plugins");
- ThrowMsg(Exceptions::InternalError, "Failed to create directory for plugins");
+ ThrowMsg(Exceptions::FileOperationFailed,
+ "Failed to create directory for plugins");
}
- LogDebug("Copying plugins to: " <<m_npdestination);
+ LogDebug("Copying plugins to: " << m_npdestination);
/* 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++) {
+ for (std::list<std::string>::const_iterator it = m_nplugins.begin();
+ it != m_nplugins.end(); ++it)
+ {
LogDebug("Copying plugin file: " << (*it));
source = m_npsource + "/" + (*it);
destination = m_npdestination + (*it);
- 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");
+ if (rename(source.c_str(), destination.c_str()) != 0) {
+ LogError("Failed to move " << source << " to " << destination);
+ LogError("(errno: " << errno << ")");
+ ThrowMsg(Exceptions::FileOperationFailed, "Failed to copy plugin file");
}
}
LogDebug("Removing unnecessary directory: " << source);
/* Remove source directory with plugins (possibly for multiple
* architectures). */
- if(!WrtUtilRemove(source)){
+ if (!WrtUtilRemove(source)) {
LogError("Failed to plugins source remove directory");
- ThrowMsg(Exceptions::InternalError, "Failed to plugins source remove directory");
+ 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()
{
LogDebug("Plugins copy task finished");
}
-
} //namespace WidgetInstall
} //namespace Jobs