+++ /dev/null
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file task_plugin_copy.cpp
- * @author Marcin Kaminski (marcin.ka@samsung.com)
- * @version 1.0
- * @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>
-/* Headers needed for listing directories */
-#include <sys/stat.h>
-#include <dirent.h>
-/* Installation expceptions support */
-#include <dpl/exception.h>
-#include <cerrno>
-
-/* wrt-installer has to copy plugins for ARM architecture
- * when running on target or for i586 architecture if launched
- * on SDK emulator. */
-#ifdef __arm__
-const std::string plugins_dir = "arm";
-#else
-const std::string plugins_dir = "i586";
-#endif
-
-namespace {
-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)
-{
- LogDebug("Starting widget plugins copy task");
- AddStep(&TaskPluginsCopy::StepFindPlugins);
- AddStep(&TaskPluginsCopy::StepCopyPlugins);
- AddStep(&TaskPluginsCopy::StepCopyingFinished);
- LogDebug("Widget plugins copy task ended");
- m_npsource = m_context.locations->getSourceDir() + PackagePluginsDir
- + plugins_dir;
- m_npdestination = m_context.locations->getPackageInstallationDir()
- + 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");
- SwitchToStep(&TaskPluginsCopy::StepCopyingFinished);
- return;
- }
-
- /* Find all .so files and store their names in list */
- DIR *dir;
- struct stat st;
- LogDebug("Opening plugins directory");
- dir = opendir(m_npsource.c_str());
- if (dir == NULL) {
- LogError("Unable to open 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 */
- 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)
- {
- LogError("Directory detected instead of plugin file: "
- << 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());
- }
- ThrowMsg(
- Exceptions::PluginsSubdirectory,
- "Subdirectories inside plugins directory are not supported");
- } else {
- continue;
- }
- }
-
- tempname = std::string(entry.d_name);
- /* Check whether file extension is ".so" */
- if (tempname.compare(tempname.size() - ext.size(), ext.size(),
- ext) == 0)
- {
- /* Plugin file found */
- LogDebug("Plugin file found: " << tempname);
- m_nplugins.push_back(tempname);
- } else {
- /* Non-.so file found in plugins directory- skipping */
- 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());
- }
- /* If no .so files found (list is empty) abort taks*/
- 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("Plugins finding step ended");
-}
-
-void TaskPluginsCopy::StepCopyPlugins()
-{
- LogDebug("Starting plugins copying step");
- std::string source;
- std::string destination;
-
- /* Create new directory for plugins (data/.netscape/plugins/) */
- LogDebug("Creating destination plugin directory");
- if (!WrtUtilMakeDir(m_npdestination, InstallationPluginsDirMode)) {
- LogError("Failed to create directory for plugins");
- ThrowMsg(Exceptions::FileOperationFailed,
- "Failed to create directory for plugins");
- }
-
- 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)
- {
- 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::FileOperationFailed, "Failed to copy plugin file");
- }
- }
-
- /* Remove last part of path in source directory path
- * (that is "arm" or "i586" depending on architecture) */
- size_t position = m_npsource.find_last_of('/');
- source = m_npsource.substr(0, position);
- LogDebug("Removing unnecessary directory: " << source);
- /* Remove source directory with plugins (possibly for multiple
- * architectures). */
- if (!WrtUtilRemove(source)) {
- LogError("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
+++ /dev/null
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file task_plugin_copy.h
- * @author Marcin Kaminski (marcin.ka@samsung.com)
- * @version 1.0
- * @brief Copying plugins delivered in widget package.
- */
-
-#ifndef WRT_INSTALLER_SRC_JOBS_WIDGET_INSTALL_TASK_PLUGINS_COPY_H
-#define WRT_INSTALLER_SRC_JOBS_WIDGET_INSTALL_TASK_PLUGINS_COPY_H
-
-class InstallerContext;
-
-#include <string>
-#include <dpl/task.h>
-#include <dpl/string.h>
-#include <list>
-
-namespace Jobs {
-namespace WidgetInstall {
-class TaskPluginsCopy : public DPL::TaskDecl<TaskPluginsCopy>
-{
- public:
- TaskPluginsCopy(InstallerContext &context);
-
- private:
- /* Widget installer context */
- InstallerContext &m_context;
- /* Path to plugins directory in unpacked widget*/
- std::string m_npsource;
- /* Path to plugins destination (install) directory */
- std::string m_npdestination;
- /* List of found .so files to copy*/
- std::list<std::string> m_nplugins;
-
- /* Plugins copying task steps. */
- void StepFindPlugins();
- void StepCopyPlugins();
- void StepCopyingFinished();
-};
-} //namespace WidgetInstall
-} //namespace Jobs
-
-#endif /* WRT_INSTALLER_SRC_JOBS_WIDGET_INSTALL_TASK_PLUGINS_COPY_H */