#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>
/* 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
}
/* 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(
}
}
- 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)
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());
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");
}
/* 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);
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");
}
}
* 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()