summaryrefslogtreecommitdiff
path: root/src/jobs
diff options
context:
space:
mode:
authorTaejeong Lee <taejeong.lee@samsung.com>2012-08-31 21:19:14 +0900
committerTaejeong Lee <taejeong.lee@samsung.com>2012-08-31 21:22:44 +0900
commit5ed3165dbb0d38b93fdfd6791d35815b02b9d365 (patch)
tree4924cb89d18cd5302a4e01b2f4e38010c848f3b3 /src/jobs
parent2ce76b65237f65d053c6e72c4a39dcaa38b83843 (diff)
downloadwrt-installer-master.tar.gz
wrt-installer-master.tar.bz2
wrt-installer-master.zip
Diffstat (limited to 'src/jobs')
-rw-r--r--src/jobs/job.cpp2
-rwxr-xr-xsrc/jobs/widget_install/job_widget_install.cpp69
-rw-r--r--src/jobs/widget_install/job_widget_install.h4
-rw-r--r--src/jobs/widget_install/manifest.cpp1
-rw-r--r--src/jobs/widget_install/task_ace_check.cpp2
-rwxr-xr-xsrc/jobs/widget_install/task_certify.cpp2
-rw-r--r--src/jobs/widget_install/task_commons.h2
-rw-r--r--src/jobs/widget_install/task_db_update.cpp102
-rw-r--r--src/jobs/widget_install/task_db_update.h3
-rw-r--r--src/jobs/widget_install/task_encrypt_resource.cpp12
-rw-r--r--src/jobs/widget_install/task_file_manipulation.cpp129
-rw-r--r--src/jobs/widget_install/task_file_manipulation.h48
-rw-r--r--src/jobs/widget_install/task_install_ospsvc.cpp3
-rw-r--r--src/jobs/widget_install/task_manifest_file.cpp40
-rw-r--r--src/jobs/widget_install/task_manifest_file.h2
-rw-r--r--src/jobs/widget_install/task_prepare_files.cpp27
-rw-r--r--src/jobs/widget_install/task_prepare_files.h2
-rw-r--r--src/jobs/widget_install/task_private_storage.cpp3
-rw-r--r--src/jobs/widget_install/task_recovery.cpp7
-rw-r--r--src/jobs/widget_install/task_remove_backup.cpp12
-rw-r--r--src/jobs/widget_install/task_unzip.cpp44
-rw-r--r--src/jobs/widget_install/task_unzip.h3
-rw-r--r--src/jobs/widget_install/task_update_files.cpp16
-rwxr-xr-xsrc/jobs/widget_install/task_widget_config.cpp274
-rwxr-xr-xsrc/jobs/widget_install/task_widget_config.h41
-rwxr-xr-xsrc/jobs/widget_install/widget_install_context.h9
-rw-r--r--src/jobs/widget_uninstall/job_widget_uninstall.cpp12
-rw-r--r--src/jobs/widget_uninstall/task_remove_files.cpp4
-rw-r--r--src/jobs/widget_uninstall/task_remove_files.h6
-rw-r--r--src/jobs/widget_uninstall/uninstaller_context.h4
30 files changed, 569 insertions, 316 deletions
diff --git a/src/jobs/job.cpp b/src/jobs/job.cpp
index 70fef1a..64903b2 100644
--- a/src/jobs/job.cpp
+++ b/src/jobs/job.cpp
@@ -73,7 +73,7 @@ void Job::Resume()
m_paused = false;
// Trigger next steps
- CONTROLLER_POST_EVENT(InstallerController,
+ CONTROLLER_POST_EVENT(Logic::InstallerController,
InstallerControllerEvents::NextStepEvent(this));
}
diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp
index 24db446..059a957 100755
--- a/src/jobs/widget_install/job_widget_install.cpp
+++ b/src/jobs/widget_install/job_widget_install.cpp
@@ -30,6 +30,7 @@
#include <dpl/assert.h>
#include <dpl/sstream.h>
#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/utils/file_utils.h>
#include "root_parser.h"
#include "widget_parser.h"
#include "parser_runner.h"
@@ -38,6 +39,7 @@
#include <widget_install/task_certify.h>
#include <widget_install/task_widget_config.h>
#include <widget_install/task_db_update.h>
+#include <widget_install/task_file_manipulation.h>
#include <widget_install/task_ace_check.h>
#include <widget_install/task_smack.h>
#include <widget_install/task_manifest_file.h>
@@ -130,9 +132,9 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
m_exceptionCaught(Exceptions::Success)
{
// Check installation type (config.xml or widget.wgt)
- m_installerContext.browserRequest = hasExtension(widgetPath, XML_EXTENSION);
+ bool browserRequest = hasExtension(widgetPath, XML_EXTENSION);
- LogInfo("Hosted app installation: " << m_installerContext.browserRequest);
+ LogInfo("Hosted app installation: " << browserRequest);
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -146,17 +148,25 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
m_installerContext.widgetHandle = handle;
m_installerContext.m_quiet = m_jobStruct.m_quiet;
- m_installerContext.widgetConfig.pType = checkPackageType(widgetPath);
+ if(!browserRequest)
+ {
+ m_installerContext.widgetConfig.pType = checkPackageType(widgetPath);
+ }
+ else
+ {
+ m_installerContext.widgetConfig.pType = WrtDB::PKG_TYPE_TIZEN_WEBAPP;
+ }
+ LogDebug("widgetPath:" << widgetPath);
- ConfigParserData configData = getWidgetDataFromXML(widgetPath,
- m_installerContext.browserRequest,
+ ConfigParserData configData = getWidgetDataFromXML(widgetPath, browserRequest,
m_installerContext.widgetConfig.pType);
WidgetUpdateInfo update = detectWidgetUpdate(configData);
+
bool needEncryption = detectResourceEncryption(configData);
+
// Configure installation
- ConfigureResult result = ConfigureInstallation(widgetPath,
- m_installerContext.browserRequest, update);
+ ConfigureResult result = ConfigureInstallation(widgetPath, update);
if (!setTizenId(configData)) {
result = ConfigureResult::Failed;
} else {
@@ -164,6 +174,8 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
LogInfo("WidgetHandle: " << m_installerContext.widgetHandle);
LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
+ configureWidgetLocation(widgetPath, browserRequest);
+
// send start signal of pkgmgr
PkgmgrSignalSingleton::Instance().setPkgname(
DPL::ToUTF8String(
@@ -172,22 +184,25 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
PKGMGR_START_KEY,
PKGMGR_START_INSTALL);
}
-
if (result == ConfigureResult::Ok) {
LogInfo("Configure installation succeeded");
AddTask(new TaskRecovery(m_installerContext));
// Create installation tasks
- if (!m_installerContext.browserRequest) {
+ if (!m_installerContext.locations->browserRequest()) {
AddTask(new TaskUnzip(m_installerContext));
}
AddTask(new TaskWidgetConfig(m_installerContext));
+ if (m_installerContext.locations->browserRequest()) {
+ AddTask(new TaskPrepareFiles(m_installerContext));
+ }
AddTask(new TaskCertify(m_installerContext));
if (needEncryption) {
AddTask(new TaskEncryptResource(m_installerContext));
}
AddTask(new TaskDbUpdate(m_installerContext));
+ AddTask(new TaskFileManipulation(m_installerContext));
// TODO: Update progress information for this task
AddTask(new TaskPrivateStorage(m_installerContext));
@@ -206,10 +221,13 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
LogInfo("Configure installation updated");
LogInfo("Widget Update");
- if (!m_installerContext.browserRequest) {
+ if (!m_installerContext.locations->browserRequest()) {
AddTask(new TaskUnzip(m_installerContext));
}
AddTask(new TaskWidgetConfig(m_installerContext));
+ if (m_installerContext.locations->browserRequest()) {
+ AddTask(new TaskPrepareFiles(m_installerContext));
+ }
AddTask(new TaskCertify(m_installerContext));
AddTask(new TaskUpdateFiles(m_installerContext));
@@ -339,9 +357,24 @@ DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const
return m_installerContext.widgetHandle;
}
+void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, bool browserRequest)
+{
+ Try
+ {
+ m_installerContext.locations = WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
+ widgetPath, browserRequest, m_installerContext.widgetConfig.pType);
+ }
+ Catch(FileUtils::CreateDirectoryException)
+ {
+ LogError("Failed to create temporary path for widget");
+ ReThrowMsg(FileUtils::CreateDirectoryException, "Failed to create temporary path for widget");
+ }
+
+ LogInfo("widgetSource " << widgetPath);
+}
+
JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
const std::string &widgetSource,
- bool fromBrowser,
const WidgetUpdateInfo &update)
{
LogInfo(
@@ -401,20 +434,6 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
LogInfo("Whether widget policy allow proceed: " << canProceed);
// Init installer context
- m_installerContext.widgetSource = widgetSource;
- m_installerContext.tempWidgetPath = std::string();
-
- // setup config xml path
- if (fromBrowser) {
- LogInfo("widgetSource " << widgetSource);
- size_t slash = widgetSource.find_last_of("\\/");
- if (std::string::npos != slash) {
- m_installerContext.tempWidgetPath = widgetSource.substr(0, slash+1);
- } else {
- m_installerContext.tempWidgetPath = ".";
- }
- }
-
m_installerContext.installStep = InstallerContext::INSTALL_START;
m_installerContext.job = this;
m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
diff --git a/src/jobs/widget_install/job_widget_install.h b/src/jobs/widget_install/job_widget_install.h
index 23b5b26..6230d17 100644
--- a/src/jobs/widget_install/job_widget_install.h
+++ b/src/jobs/widget_install/job_widget_install.h
@@ -46,7 +46,7 @@ class JobWidgetInstall :
InstallerContext m_installerContext;
- //TODO move it to base class of all jobs
+ //TODO move it to base class of all jobs -> make it base template class??
Exceptions::Type m_exceptionCaught;
std::string m_exceptionMessage;
WidgetUpdateInfo m_widgetUpdateInfo;
@@ -57,7 +57,6 @@ class JobWidgetInstall :
};
ConfigureResult ConfigureInstallation(const std::string &widgetSource,
- bool fromBrowser,
const WidgetUpdateInfo &update);
static WrtDB::ConfigParserData getWidgetDataFromXML(
const std::string &widgetSource,
@@ -69,6 +68,7 @@ class JobWidgetInstall :
const OptionalWidgetVersion &incomingVersion) const;
bool setTizenId(const WrtDB::ConfigParserData &configInfo);
void displayWidgetInfo();
+ void configureWidgetLocation(const std::string & widgetPath, bool browserRequest);
WrtDB::PackagingType checkPackageType(
const std::string &widgetSorce);
diff --git a/src/jobs/widget_install/manifest.cpp b/src/jobs/widget_install/manifest.cpp
index e828d78..039bbb4 100644
--- a/src/jobs/widget_install/manifest.cpp
+++ b/src/jobs/widget_install/manifest.cpp
@@ -108,7 +108,6 @@ void writeAttribute(xmlTextWriterPtr writer, const char * name, const char * bod
}
}
-//TODO shouldn't XML file creation happen here? If no, this method is not needed
void Manifest::generate(DPL::String filename)
{
xmlTextWriterPtr writer;
diff --git a/src/jobs/widget_install/task_ace_check.cpp b/src/jobs/widget_install/task_ace_check.cpp
index 3962441..192247f 100644
--- a/src/jobs/widget_install/task_ace_check.cpp
+++ b/src/jobs/widget_install/task_ace_check.cpp
@@ -95,7 +95,7 @@ void TaskAceCheck::StepAceCheck()
void TaskAceCheck::StepProcessAceResponse()
{
- if (m_context.browserRequest) {
+ if (m_context.locations->browserRequest()) {
return;
}
diff --git a/src/jobs/widget_install/task_certify.cpp b/src/jobs/widget_install/task_certify.cpp
index 2c2e7b5..ab6d26c 100755
--- a/src/jobs/widget_install/task_certify.cpp
+++ b/src/jobs/widget_install/task_certify.cpp
@@ -175,7 +175,7 @@ void TaskCertify::stepSignature()
{
LogInfo("enter");
- std::string widgetPath = m_contextData.tempWidgetRoot + "/";
+ std::string widgetPath = m_contextData.locations->getTemporaryRootDir() + "/";
SignatureFileInfoSet signatureFiles;
SignatureFinder signatureFinder(widgetPath);
diff --git a/src/jobs/widget_install/task_commons.h b/src/jobs/widget_install/task_commons.h
index 76306db..940c710 100644
--- a/src/jobs/widget_install/task_commons.h
+++ b/src/jobs/widget_install/task_commons.h
@@ -27,6 +27,8 @@
namespace Jobs {
namespace WidgetInstall {
+//TODO make directory like jobs common?
+
void removeTemporaryDir(const std::string& path);
std::string createTempPath();
diff --git a/src/jobs/widget_install/task_db_update.cpp b/src/jobs/widget_install/task_db_update.cpp
index 4804bce..5b02a95 100644
--- a/src/jobs/widget_install/task_db_update.cpp
+++ b/src/jobs/widget_install/task_db_update.cpp
@@ -19,8 +19,7 @@
* @version 1.0
* @brief Implementation file for installer task database updating
*/
-#include <time.h>
-#include <sys/stat.h>
+//#include <time.h>
#include <widget_install/task_db_update.h>
#include <widget_install/job_widget_install.h>
#include <widget_install/widget_install_errors.h>
@@ -33,7 +32,6 @@
#include <dpl/assert.h>
#include <dpl/wrt-dao-ro/global_config.h>
#include <string>
-//#include <widget_controller.h>
#include <Ecore_File.h>
#include <sstream>
@@ -46,46 +44,8 @@ TaskDbUpdate::TaskDbUpdate(InstallerContext& context) :
m_context(context)
{
AddStep(&TaskDbUpdate::StepDbUpdate);
- AddStep(&TaskDbUpdate::StepCreateDirs);
- AddStep(&TaskDbUpdate::StepRenamePath);
-
AddAbortStep(&TaskDbUpdate::StepAbortDBUpdate);
- AddAbortStep(&TaskDbUpdate::StepAbortRenamePath);
-}
-
-void TaskDbUpdate::StepCreateDirs()
-{
- std::ostringstream widgetPath;
- DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
- if (pkgname.IsNull()) {
- ThrowMsg(Exceptions::InternalError, "No Package name exists.");
- }
-
- widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- widgetPath << pkgname << "/";
-
- std::string widgetBinPath = widgetPath.str();
- std::string widgetSrcPath = widgetPath.str();
-
- _WrtMakeDir(widgetPath.str().c_str(), 0755, WRT_FILEUTILS_RECUR);
-
- // If pakcage type is widget with osp service, we don't need to make bin
- // and src directory
- if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
- LogDebug("Doesn't need to create resource directory");
- } else {
- LogDebug("Create resource directory");
- widgetBinPath += GlobalConfig::GetUserWidgetExecPath();
- _WrtMakeDir(widgetBinPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
-
- widgetSrcPath += GlobalConfig::GetWidgetSrcPath();
- _WrtMakeDir(widgetSrcPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
- }
-
- m_context.job->UpdateProgress(
- InstallerContext::INSTALL_DIR_CREATE,
- "Widget Directory Created");
}
void TaskDbUpdate::StepDbUpdate()
@@ -139,45 +99,6 @@ void TaskDbUpdate::StepDbUpdate()
"Widget DB UPDATE Finished");
}
-void TaskDbUpdate::StepRenamePath()
-{
- DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
- if (pkgname.IsNull()) {
- ThrowMsg(Exceptions::InternalError, "No Package name exists.");
- }
-
- if (!_WrtUtilRemoveDir(m_context.installPath.c_str())) {
- _WrtUtilChangeDir(GlobalConfig::GetUserInstalledWidgetPath());
- ThrowMsg(Exceptions::RemovingFolderFailure,
- "Error occurs during removing existing folder");
- }
-
- if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
- LogDebug("Copy file from temp directory to " <<
- m_context.installPath);
-
- if (rename(m_context.tempWidgetPath.c_str(),
- m_context.installPath.c_str()) < 0) {
- ThrowMsg(Exceptions::UnknownError,
- "Error occurs during renaming widget folder");
- }
- } else {
- LogDebug("Copy file from temp directory to " <<
- m_context.installPath);
-
- if (!m_context.browserRequest) {
- if (rename(m_context.tempWidgetRoot.c_str(), m_context.installPath.c_str()) < 0) {
- ThrowMsg(Exceptions::UnknownError,
- "Error occurs during renaming widget folder");
- }
- }
- }
-
- m_context.job->UpdateProgress(
- InstallerContext::INSTALL_RENAME_PATH,
- "Widget Rename path Finished");
-}
-
void TaskDbUpdate::StepAbortDBUpdate()
{
LogWarning("[DB Update Task] Aborting... (DB Clean)");
@@ -196,26 +117,5 @@ void TaskDbUpdate::StepAbortDBUpdate()
}
}
-void TaskDbUpdate::StepAbortRenamePath()
-{
- LogDebug("[Rename Widget Path] Aborting.... (Rename path)");
- Assert(!!m_context.widgetHandle);
- std::ostringstream widgetPath;
- widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- widgetPath << *m_context.widgetConfig.pkgname;
-
- struct stat fileInfo;
- if (stat(widgetPath.str().c_str(), &fileInfo) != 0) {
- LogError("Failed to get widget file path : " <<widgetPath.str());
- return;
- }
-
- if (rename(widgetPath.str().c_str(),
- m_context.tempWidgetPath.c_str()) < 0) {
- LogError("Failed to rename");
- //Ignoring failures in Abort
- }
- LogDebug("Rename widget path sucessful!");
-}
} //namespace WidgetInstall
} //namespace Jobs
diff --git a/src/jobs/widget_install/task_db_update.h b/src/jobs/widget_install/task_db_update.h
index 59e9c37..3f76680 100644
--- a/src/jobs/widget_install/task_db_update.h
+++ b/src/jobs/widget_install/task_db_update.h
@@ -34,12 +34,9 @@ class TaskDbUpdate :
private:
InstallerContext& m_context;
- void StepCreateDirs();
void StepDbUpdate();
- void StepRenamePath();
void StepAbortDBUpdate();
- void StepAbortRenamePath();
public:
TaskDbUpdate(InstallerContext& context);
diff --git a/src/jobs/widget_install/task_encrypt_resource.cpp b/src/jobs/widget_install/task_encrypt_resource.cpp
index 6414eb7..91cef03 100644
--- a/src/jobs/widget_install/task_encrypt_resource.cpp
+++ b/src/jobs/widget_install/task_encrypt_resource.cpp
@@ -77,13 +77,7 @@ void TaskEncryptResource::StepEncryptResource()
m_resEnc->CreateEncryptionKey(DPL::ToUTF8String(*m_context.
widgetConfig.pkgname));
- if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
- tempInstalledPath = m_context.tempWidgetPath;
- } else {
- tempInstalledPath = m_context.tempWidgetRoot;
- }
-
- EncryptDirectory(tempInstalledPath);
+ EncryptDirectory(m_context.locations->getTemporaryRootDir());
}
void TaskEncryptResource::EncryptDirectory(std::string path)
@@ -173,8 +167,8 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
}
std::string realPath = fileName;
- realPath.replace(0, tempInstalledPath.length(),
- m_context.installPath);
+ realPath.replace(0, m_context.locations->getTemporaryRootDir().length(),
+ m_context.locations->getPackageInstallationDir());
WrtDB::EncryptedFileInfo info;
info.fileName = DPL::FromUTF8String(realPath);
diff --git a/src/jobs/widget_install/task_file_manipulation.cpp b/src/jobs/widget_install/task_file_manipulation.cpp
new file mode 100644
index 0000000..1bf51a8
--- /dev/null
+++ b/src/jobs/widget_install/task_file_manipulation.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2011 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_db_update.cpp
+ * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief Implementation file for installer task database updating
+ */
+#include <sys/stat.h>
+#include <widget_install/task_file_manipulation.h>
+#include <widget_install/job_widget_install.h>
+#include <widget_install/widget_install_errors.h>
+#include <widget_install/widget_install_context.h>
+#include <dpl/utils/wrt_utility.h>
+#include <dpl/foreach.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <string>
+
+using namespace WrtDB;
+
+namespace Jobs {
+namespace WidgetInstall {
+TaskFileManipulation::TaskFileManipulation(InstallerContext& context) :
+ DPL::TaskDecl<TaskFileManipulation>(this),
+ m_context(context)
+{
+ AddStep(&TaskFileManipulation::StepCreateDirs);
+ AddStep(&TaskFileManipulation::StepRenamePath);
+
+ AddAbortStep(&TaskFileManipulation::StepAbortRenamePath);
+}
+
+void TaskFileManipulation::StepCreateDirs()
+{
+ std::string widgetPath;
+ DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
+ if (pkgname.IsNull()) {
+ ThrowMsg(Exceptions::InternalError, "No Package name exists.");
+ }
+
+ widgetPath = m_context.locations->getPackageInstallationDir();
+
+ std::string widgetBinPath = m_context.locations->getBinaryDir();
+ std::string widgetSrcPath = m_context.locations->getSourceDir();
+
+ _WrtMakeDir(widgetPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
+
+ // If package type is widget with osp service, we don't need to make bin
+ // and src directory
+ if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
+ LogDebug("Doesn't need to create resource directory");
+ } else {
+ LogDebug("Create resource directory");
+ _WrtMakeDir(widgetBinPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
+ _WrtMakeDir(widgetSrcPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
+ }
+
+ m_context.job->UpdateProgress(
+ InstallerContext::INSTALL_DIR_CREATE,
+ "Widget Directory Created");
+}
+
+void TaskFileManipulation::StepRenamePath()
+{
+ std::string instDir;
+ DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
+ if (pkgname.IsNull()) {
+ ThrowMsg(Exceptions::InternalError, "No Package name exists.");
+ }
+
+ if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
+ instDir = m_context.locations->getPackageInstallationDir();
+ } else {
+ instDir = m_context.locations->getSourceDir();
+ }
+
+ LogDebug("Copy file from temp directory to " << instDir);
+ if (!_WrtUtilRemoveDir(instDir.c_str())) {
+ ThrowMsg(Exceptions::RemovingFolderFailure,
+ "Error occurs during removing existing folder");
+ }
+
+ if (!(rename(m_context.locations->getTemporaryPackageDir().c_str(), instDir.c_str()) == 0)) {
+ ThrowMsg(Exceptions::UnknownError,
+ "Error occurs during renaming widget folder");
+ }
+
+ m_context.job->UpdateProgress(
+ InstallerContext::INSTALL_RENAME_PATH,
+ "Widget Rename path Finished");
+}
+
+void TaskFileManipulation::StepAbortRenamePath()
+{
+ LogDebug("[Rename Widget Path] Aborting.... (Rename path)");
+ Assert(!!m_context.widgetHandle);
+ std::string widgetPath;
+ if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
+ widgetPath = m_context.locations->getPackageInstallationDir();
+ } else {
+ widgetPath = m_context.locations->getSourceDir();
+ }
+ struct stat fileInfo;
+ if (stat(widgetPath.c_str(), &fileInfo) != 0) {
+ LogError("Failed to get widget file path : " << widgetPath);
+ return;
+ }
+
+ if (!(rename(widgetPath.c_str(), m_context.locations->getTemporaryPackageDir().c_str()) == 0)) {
+ LogError("Failed to rename");
+ }
+ LogDebug("Rename widget path sucessful!");
+}
+} //namespace WidgetInstall
+} //namespace Jobs
diff --git a/src/jobs/widget_install/task_file_manipulation.h b/src/jobs/widget_install/task_file_manipulation.h
new file mode 100644
index 0000000..162dbbf
--- /dev/null
+++ b/src/jobs/widget_install/task_file_manipulation.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011 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_db_update.h
+ * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief Header file for installer task database updating
+ */
+#ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_FILE_MANIPULATION_H
+#define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_FILE_MANIPULATION_UPDATE_H
+
+#include <dpl/task.h>
+
+class InstallerContext;
+
+namespace Jobs {
+namespace WidgetInstall {
+class TaskFileManipulation :
+ public DPL::TaskDecl<TaskFileManipulation>
+{
+ private:
+ InstallerContext& m_context;
+
+ void StepCreateDirs();
+ void StepRenamePath();
+
+ void StepAbortRenamePath();
+
+ public:
+ TaskFileManipulation(InstallerContext& context);
+};
+} //namespace WidgetInstall
+} //namespace Jobs
+
+#endif // INSTALLER_CORE_JOS_WIDGET_INSTALL_FILE_MANIPULATION_H
diff --git a/src/jobs/widget_install/task_install_ospsvc.cpp b/src/jobs/widget_install/task_install_ospsvc.cpp
index 0a26435..cb7f1fa 100644
--- a/src/jobs/widget_install/task_install_ospsvc.cpp
+++ b/src/jobs/widget_install/task_install_ospsvc.cpp
@@ -54,8 +54,7 @@ void TaskInstallOspsvc::StepInstallOspService()
LogInfo("Step: installation for osp service");
std::ostringstream commStr;
- commStr << OSP_INSTALL_STR << GlobalConfig::GetUserInstalledWidgetPath();
- commStr << "/" << m_context.widgetConfig.pkgname;
+ commStr << OSP_INSTALL_STR << m_context.locations->getPackageInstallationDir();
//commStr << " 2>&1";
LogDebug("osp install command : " << commStr.str());
diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp
index e6a8dce..d9104bf 100644
--- a/src/jobs/widget_install/task_manifest_file.cpp
+++ b/src/jobs/widget_install/task_manifest_file.cpp
@@ -131,10 +131,7 @@ void TaskManifestFile::stepCreateExecFile()
ThrowMsg(Exceptions::InternalError, "No Package name exists.");
}
- real_path << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- real_path << pkgname << "/";
- real_path << GlobalConfig::GetUserWidgetExecPath() << "/" <<
- m_context.widgetHandle;
+ real_path << m_context.locations->getBinaryDir() << "/" << m_context.widgetHandle;
std::string clientExeStr = GlobalConfig::GetWrtClientExec();
LogInfo("link -s " << clientExeStr << " " << real_path.str());
@@ -175,14 +172,8 @@ void TaskManifestFile::stepCopyIconFiles()
std::ostringstream targetFile;
if (!!src) {
- if (m_context.browserRequest) {
- size_t pos = m_context.widgetSource.rfind("/");
- sourceFile << m_context.widgetSource.substr(0, pos+1);
- } else {
- sourceFile << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- sourceFile << pkgname << "/";
- sourceFile << GlobalConfig::GetWidgetSrcPath() << "/";
- }
+
+ sourceFile << m_context.locations->getSourceDir() << "/";
if (!i.empty()) {
sourceFile << "locales/" << i << "/";
@@ -193,9 +184,11 @@ void TaskManifestFile::stepCopyIconFiles()
targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
targetFile << getIconTargetFilename(i);
- if (m_context.browserRequest) {
- m_context.installedIconPath = targetFile.str();
+ if (m_context.locations->browserRequest())
+ {
+ m_context.locations->setIconTargetFilenameForLocale(targetFile.str());
}
+
} else {
//Use WRT default (not from the widget) only if widget default (not
// localized) doesn't exist.
@@ -256,8 +249,7 @@ void TaskManifestFile::stepBackupIconFiles()
{
LogDebug("Backup Icon Files");
- backup_dir << GlobalConfig::GetUserInstalledWidgetPath();
- backup_dir << "/" << m_context.widgetConfig.pkgname;
+ backup_dir << m_context.locations->getPackageInstallationDir();
backup_dir << "/" << "backup" << "/";
backupIconFiles();
@@ -354,6 +346,7 @@ void TaskManifestFile::stepFinalize()
LogInfo("Finished ManifestFile step");
}
+
void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
const DPL::String& key,
const DPL::String& languageTag)
@@ -593,8 +586,7 @@ void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp)
}
std::ostringstream path;
- path << GlobalConfig::GetUserInstalledWidgetPath() << "/" << *pkgname << "/";
- path << GlobalConfig::GetUserWidgetExecPath() << "/" << *m_context.widgetHandle;
+ path << m_context.locations->getBinaryDir() << "/" << *m_context.widgetHandle;
uiApp.setExec(DPL::FromASCIIString(path.str()));
}
@@ -717,7 +709,9 @@ void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
}
}
-void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag, const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list, bool & defaultIconSaved)
+void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag,
+ const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list,
+ bool & defaultIconSaved)
{
DPL::String locale;
if (!!tag)
@@ -738,7 +732,8 @@ void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::Opti
}
if (!!src) {
DPL::String iconText;
- iconText += /*DPL::FromASCIIString(GlobalConfig::GetUserWidgetDesktopIconPath()) + L"/" +*/ getIconTargetFilename(language);
+ iconText += getIconTargetFilename(language);
+
if(!locale.empty())
{
uiApp.addIcon(IconType(iconText,locale));
@@ -772,10 +767,11 @@ void TaskManifestFile::setWidgetManifest(Manifest & manifest)
void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
{
uiApp.setNodisplay(false);
- //TODO(t.iwanek):
- //There is no "X-TIZEN-PackageType=wgt", there is not field in manifest
+ //TODO
+ //There is no "X-TIZEN-PackageType=wgt"
//There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str()
//There is no Comment in pkgmgr "Comment=Widget application"
+ //that were in desktop file
}
void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp)
diff --git a/src/jobs/widget_install/task_manifest_file.h b/src/jobs/widget_install/task_manifest_file.h
index d06b3d2..57c44f4 100644
--- a/src/jobs/widget_install/task_manifest_file.h
+++ b/src/jobs/widget_install/task_manifest_file.h
@@ -101,11 +101,11 @@ class TaskManifestFile :
//for widget update
void backupIconFiles();
void getFileList(const char* path, std::list<std::string> &list);
+ DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
static void saveLocalizedKey(std::ofstream &file,
const DPL::String& key,
const DPL::String& languageTag);
- DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
static const char * encoding;
diff --git a/src/jobs/widget_install/task_prepare_files.cpp b/src/jobs/widget_install/task_prepare_files.cpp
index 50c1a58..9395094 100644
--- a/src/jobs/widget_install/task_prepare_files.cpp
+++ b/src/jobs/widget_install/task_prepare_files.cpp
@@ -41,19 +41,7 @@ TaskPrepareFiles::TaskPrepareFiles(InstallerContext &installerContext) :
m_installerContext(installerContext)
{
// Install steps
- AddStep(&TaskPrepareFiles::StepCreateTempPath);
AddStep(&TaskPrepareFiles::StepCopyFiles);
-
- AddAbortStep(&TaskPrepareFiles::StepAbort);
-}
-
-void TaskPrepareFiles::StepCreateTempPath()
-{
- /*
- * Config.xml and all icons will be copied to another location so the path
- * has to be updated.
- */
- m_installerContext.tempWidgetPath = createTempPath();
}
void TaskPrepareFiles::CopyFile(const std::string& source)
@@ -68,7 +56,7 @@ void TaskPrepareFiles::CopyFile(const std::string& source)
if(last != std::string::npos) {
filename = source.substr( last+1 );
}
- std::string target = m_installerContext.tempWidgetPath + '/' + filename;
+ std::string target = m_installerContext.locations->getTemporaryPackageDir() + '/' + filename;
LogDebug("source " << source);
LogDebug("target " << target);
@@ -100,25 +88,22 @@ void TaskPrepareFiles::CopyFile(const std::string& source)
void TaskPrepareFiles::StepCopyFiles()
{
- CopyFile(m_installerContext.widgetSource);
+ CopyFile(m_installerContext.locations->getWidgetSource());
- size_t last = m_installerContext.widgetSource.find_last_of("\\/");
+ size_t last = m_installerContext.locations->getWidgetSource().find_last_of("\\/");
std::string sourceDir = "";
if (last != std::string::npos) {
- sourceDir = m_installerContext.widgetSource.substr(0,last+1);
+ sourceDir = m_installerContext.locations->getWidgetSource().substr(0,last+1);
}
+ LogDebug("Icons copy...");
FOREACH(it, m_installerContext.widgetConfig.configInfo.iconsList) {
std::ostringstream os;
+ LogDebug("Coping: " << sourceDir << DPL::ToUTF8String(it->src));
os << sourceDir << DPL::ToUTF8String(it->src);
CopyFile(os.str());
}
}
-void TaskPrepareFiles::StepAbort()
-{
- removeTemporaryDir(m_installerContext.tempWidgetPath);
-}
-
} // namespace WidgetInstall
} // namespace Jobs
diff --git a/src/jobs/widget_install/task_prepare_files.h b/src/jobs/widget_install/task_prepare_files.h
index 27ad5d6..7db10cf 100644
--- a/src/jobs/widget_install/task_prepare_files.h
+++ b/src/jobs/widget_install/task_prepare_files.h
@@ -39,9 +39,7 @@ private:
void CopyFile(const std::string& source);
// Steps
- void StepCreateTempPath();
void StepCopyFiles();
- void StepAbort();
public:
explicit TaskPrepareFiles(InstallerContext &installerContext);
diff --git a/src/jobs/widget_install/task_private_storage.cpp b/src/jobs/widget_install/task_private_storage.cpp
index b88211c..7b5cb85 100644
--- a/src/jobs/widget_install/task_private_storage.cpp
+++ b/src/jobs/widget_install/task_private_storage.cpp
@@ -66,8 +66,7 @@ void TaskPrivateStorage::StepCreateDirectory()
std::ostringstream widgetPath;
DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
if(!pkgname.IsNull()) {
- widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- widgetPath << pkgname << "/";
+ widgetPath << m_context.locations->getPackageInstallationDir() << "/";
} else {
ThrowMsg(Exceptions::InternalError, "No Package name exists.");
}
diff --git a/src/jobs/widget_install/task_recovery.cpp b/src/jobs/widget_install/task_recovery.cpp
index d6eba3d..6ff2218 100644
--- a/src/jobs/widget_install/task_recovery.cpp
+++ b/src/jobs/widget_install/task_recovery.cpp
@@ -55,16 +55,15 @@ void TaskRecovery::StepCreateCheckFile()
{
LogInfo("Step: create information file for recovery");
- std::string fileName;
- size_t pos = m_context.widgetSource.rfind("/");
+ size_t pos = m_context.locations->getWidgetSource().rfind("/");
std::ostringstream infoPath;
infoPath << GlobalConfig::GetTempInstallInfoPath();
infoPath << "/";
- infoPath << m_context.widgetSource.substr(pos+1);
+ infoPath << m_context.locations->getWidgetSource().substr(pos+1);
FILE *temp = fopen(infoPath.str().c_str(), "w+");
if (temp != NULL) {
- fputs(m_context.widgetSource.c_str(), temp);
+ fputs(m_context.locations->getWidgetSource().c_str(), temp);
fsync(temp->_fileno);
fclose(temp);
diff --git a/src/jobs/widget_install/task_remove_backup.cpp b/src/jobs/widget_install/task_remove_backup.cpp
index d94c4cc..77e0f4d 100644
--- a/src/jobs/widget_install/task_remove_backup.cpp
+++ b/src/jobs/widget_install/task_remove_backup.cpp
@@ -73,8 +73,7 @@ void TaskRemoveBackupFiles::StepDeleteDB()
void TaskRemoveBackupFiles::StepRemoveBackupFiles()
{
std::ostringstream backupDir;
- backupDir << GlobalConfig::GetUserInstalledWidgetPath();
- backupDir << "/" << m_context.widgetConfig.pkgname << "/" << "backup";
+ backupDir << m_context.locations->getBackupDir();
if (_WrtUtilRemoveDir(backupDir.str().c_str())) {
LogDebug("Success to remove backup files : " << backupDir.str());
@@ -84,12 +83,11 @@ void TaskRemoveBackupFiles::StepRemoveBackupFiles()
"Error occurs during removing existing folder");
}
- if (_WrtUtilRemoveDir(m_context.tempWidgetPath.c_str())) {
- LogDebug("Success to remove temp directory : " <<
- m_context.tempWidgetPath);
+ std::string tmp = m_context.locations->getTemporaryPackageDir();
+ if (_WrtUtilRemoveDir(tmp.c_str())) {
+ LogDebug("Success to remove temp directory : " << tmp);
} else {
- LogDebug("Failed to remove temp directory : " <<
- m_context.tempWidgetPath);
+ LogDebug("Failed to remove temp directory : " << tmp);
ThrowMsg(Exceptions::RemoveBackupFailed,
"Error occurs during removing existing folder");
}
diff --git a/src/jobs/widget_install/task_unzip.cpp b/src/jobs/widget_install/task_unzip.cpp
index dd9bdc8..c5f63d3 100644
--- a/src/jobs/widget_install/task_unzip.cpp
+++ b/src/jobs/widget_install/task_unzip.cpp
@@ -70,12 +70,9 @@ TaskUnzip::TaskUnzip(InstallerContext &installerContext) :
m_installerContext(installerContext)
{
// Install steps
- AddStep(&TaskUnzip::StepCreateTempPath);
AddStep(&TaskUnzip::StepUnzipPrepare);
AddStep(&TaskUnzip::StepUnzipProgress);
AddStep(&TaskUnzip::StepUnzipFinished);
-
- AddAbortStep(&TaskUnzip::StepAbort);
}
void TaskUnzip::ExtractFile(DPL::ZipInput::File *input,
@@ -98,45 +95,18 @@ void TaskUnzip::ExtractFile(DPL::ZipInput::File *input,
}
}
-void TaskUnzip::StepCreateTempPath()
-{
- // Step succedded, save temporary widget path
- m_installerContext.tempWidgetPath = createTempPath();
- std::ostringstream path;
-
- if (m_installerContext.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
- std::ostringstream tempRoot;
- tempRoot << m_installerContext.tempWidgetPath;
- tempRoot << "/" << GlobalConfig::GetWidgetSrcPath();
- m_installerContext.tempWidgetRoot = tempRoot.str();
-
- path << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- path << m_installerContext.widgetConfig.pkgname;
- } else {
- m_installerContext.tempWidgetRoot = m_installerContext.tempWidgetPath;
- path << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- path << m_installerContext.widgetConfig.pkgname << "/";
- path << GlobalConfig::GetWidgetSrcPath();
- }
- m_installerContext.installPath = path.str();
-
- m_installerContext.job->UpdateProgress(
- InstallerContext::INSTALL_CREATE_TEMPDIR,
- "Create temporary directory for unzip");
-}
-
void TaskUnzip::StepUnzipPrepare()
{
LogInfo("Prepare to unzip...");
Try
{
- m_zip.Reset(new DPL::ZipInput(m_installerContext.widgetSource));
+ m_zip.Reset(new DPL::ZipInput(m_installerContext.locations->getWidgetSource()));
LogInfo("Widget package comment: " << m_zip->GetGlobalComment());
// Widget package must not be empty
if (m_zip->empty()) {
- ThrowMsg(Exceptions::ZipEmpty, m_installerContext.widgetSource);
+ ThrowMsg(Exceptions::ZipEmpty, m_installerContext.locations->getWidgetSource());
}
// Set iterator to first file
@@ -144,7 +114,7 @@ void TaskUnzip::StepUnzipPrepare()
}
Catch(DPL::ZipInput::Exception::OpenFailed)
{
- ReThrowMsg(Exceptions::OpenZipFailed, m_installerContext.widgetSource);
+ ReThrowMsg(Exceptions::OpenZipFailed, m_installerContext.locations->getWidgetSource());
}
}
@@ -164,7 +134,7 @@ void TaskUnzip::StepUnzipProgress()
if (fileName[fileName.size() - 1] == '/') {
// This is path
- std::string newPath = m_installerContext.tempWidgetPath + "/" +
+ std::string newPath = m_installerContext.locations->getTemporaryPackageDir() + "/" +
fileName.substr(0, fileName.size() - 1);
LogPedantic("Path to extract: " << newPath);
@@ -173,7 +143,7 @@ void TaskUnzip::StepUnzipProgress()
} else {
// This is regular file
std::string fileExtractPath =
- m_installerContext.tempWidgetPath + "/" + fileName;
+ m_installerContext.locations->getTemporaryPackageDir() + "/" + fileName;
LogPedantic("File to extract: " << fileExtractPath);
@@ -223,9 +193,5 @@ void TaskUnzip::StepUnzipFinished()
LogInfo("Unzip finished");
}
-void TaskUnzip::StepAbort()
-{
- removeTemporaryDir(m_installerContext.tempWidgetPath);
-}
} //namespace WidgetInstall
} //namespace Jobs
diff --git a/src/jobs/widget_install/task_unzip.h b/src/jobs/widget_install/task_unzip.h
index 9cb8339..13ec3c8 100644
--- a/src/jobs/widget_install/task_unzip.h
+++ b/src/jobs/widget_install/task_unzip.h
@@ -51,12 +51,9 @@ class TaskUnzip :
void EncryptionFile(const std::string &fileName);
// Steps
- void StepCreateTempPath();
-
void StepUnzipPrepare();
void StepUnzipProgress();
void StepUnzipFinished();
- void StepAbort();
public:
TaskUnzip(InstallerContext &installerContext);
diff --git a/src/jobs/widget_install/task_update_files.cpp b/src/jobs/widget_install/task_update_files.cpp
index 446c043..9e29493 100644
--- a/src/jobs/widget_install/task_update_files.cpp
+++ b/src/jobs/widget_install/task_update_files.cpp
@@ -71,13 +71,7 @@ void TaskUpdateFiles::StepCreateBackupFolder()
LogDebug("StepCreateBackupFolder");
std::ostringstream backDirPath;
- backDirPath << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
-
- backDirPath << pkgname;
- m_pkgPath = backDirPath.str();
-
- backDirPath << "/" << GetWidgetBackupDirPath() << "/";
+ backDirPath << m_context.locations->getBackupDir();
m_srcBuPath = backDirPath.str() + GlobalConfig::GetWidgetSrcPath();
LogDebug("backup resource directory path : " << m_srcBuPath);
if(!_WrtMakeDir(m_srcBuPath.c_str(), 0755, WRT_FILEUTILS_RECUR)) {
@@ -142,8 +136,8 @@ void TaskUpdateFiles::StepResourceFilesBackup()
ReadDirList(pkgSrc, resList, strlen(pkgSrc.c_str())+1);
- std::string tempSrc = m_context.tempWidgetPath;
- ReadDirList(tempSrc, tempList, strlen(m_context.tempWidgetPath.c_str())+1);
+ std::string tempSrc = m_context.locations->getTemporaryPackageDir();
+ ReadDirList(tempSrc, tempList, strlen(tempSrc.c_str())+1);
FOREACH(it, tempList) {
std::set<std::string>::iterator res;
@@ -279,9 +273,7 @@ void TaskUpdateFiles::StepAbortCreateBackupFolder()
{
LogDebug("StepAbortCreateBackupFolder");
std::ostringstream path;
- path << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- path << m_context.widgetConfig.pkgname << "/";
- path << GetWidgetBackupDirPath();
+ path << m_context.locations->getBackupDir();
LogDebug("Remove backup directory : " << path.str());
if(!_WrtUtilRemoveDir(path.str().c_str())) {
diff --git a/src/jobs/widget_install/task_widget_config.cpp b/src/jobs/widget_install/task_widget_config.cpp
index c86edaf..0e22985 100755
--- a/src/jobs/widget_install/task_widget_config.cpp
+++ b/src/jobs/widget_install/task_widget_config.cpp
@@ -19,25 +19,34 @@
* @version 1.0
* @brief Implementation file for installer task widget config
*/
-#include <string>
+
#include <sstream>
-#include <dpl/foreach.h>
+#include <string>
+#include <sys/stat.h>
+#include <dirent.h>
+
#include <dpl/errno_string.h>
-#include <dpl/wrt-dao-rw/feature_dao.h>
-#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/foreach.h>
+#include <dpl/localization/w3c_file_localization.h>
+#include <dpl/singleton_impl.h>
+#include <dpl/utils/file_utils.h>
+#include <dpl/utils/mime_type_utils.h>
+#include <dpl/utils/wrt_global_settings.h>
#include <dpl/utils/wrt_utility.h>
-#include <root_parser.h>
-#include <widget_parser.h>
-#include <parser_runner.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-rw/feature_dao.h>
+
#include <libiriwrapper.h>
-#include <widget_install/task_widget_config.h>
+#include <parser_runner.h>
+#include <root_parser.h>
+
#include <widget_install/job_widget_install.h>
-#include <widget_install/widget_install_errors.h>
+#include <widget_install/task_widget_config.h>
#include <widget_install/widget_install_context.h>
-#include <dpl/utils/file_utils.h>
-#include <dpl/utils/mime_type_utils.h>
-#include <sys/stat.h>
-#include <dpl/utils/wrt_global_settings.h>
+#include <widget_install/widget_install_errors.h>
+#include <widget_parser.h>
+#include <wrt_error.h>
+
namespace { // anonymous
const WidgetHandle WIDGET_HANDLE_START_VALUE = 1000;
@@ -45,7 +54,13 @@ const DPL::String BR = DPL::FromUTF8String("<br>");
const std::string WIDGET_NOT_COMPATIBLE = "This widget is "
"not compatible with WRT.<br><br>";
const std::string QUESTION = "Do you want to install it anyway?";
-} // namespace anonymous
+
+const char *const DEFAULT_LANGUAGE = "default";
+const size_t MAX_WIDGET_PATH_SIZE = 1024;
+
+const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
+}
+
namespace Jobs {
namespace WidgetInstall {
@@ -80,19 +95,12 @@ void TaskWidgetConfig::StepProcessConfigurationFile()
{
Try
{
- std::string path;
- LogInfo("path: " << m_installContext.tempWidgetRoot);
- if (m_installContext.browserRequest) {
- path = m_installContext.widgetSource;
- } else {
- path = m_installContext.tempWidgetRoot;
- }
+ std::string path = m_installContext.locations->getConfigurationDir();
+ LogInfo("path: " << path);
- WidgetConfigurationManagerSingleton::Instance().processFile(
- path,
- m_installContext.widgetConfig);
+ processFile(path, m_installContext.widgetConfig);
}
- Catch(WidgetConfigurationManager::Exception::ProcessFailed)
+ Catch(Exception::ConfigParseFailed)
{
LogError("Parsing failed.");
ReThrow(Exceptions::WidgetConfigFileInvalid);
@@ -102,7 +110,7 @@ void TaskWidgetConfig::StepProcessConfigurationFile()
// To get widget type for distribute WAC, TIZEN WebApp
setApplicationType();
}
- Catch(WidgetConfigurationManager::Exception::ProcessFailed)
+ Catch(Exception::ConfigParseFailed)
{
LogError("Config.xml has more than one namespace");
ReThrow(Exceptions::WidgetConfigFileInvalid);
@@ -119,7 +127,7 @@ void TaskWidgetConfig::ReadLocaleFolders()
//Adding default locale
m_localeFolders.insert(L"");
- std::string localePath = m_installContext.tempWidgetRoot + "/locales";
+ std::string localePath = m_installContext.locations->getConfigurationDir() + "/locales";
DIR* localeDir = opendir(localePath.c_str());
if (!localeDir) {
LogDebug("No /locales directory in the widget package.");
@@ -203,7 +211,7 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
DPL::String relativePath = pathPrefix + *path;
DPL::String absolutePath = DPL::FromUTF8String(
- m_installContext.tempWidgetRoot) + L"/" + relativePath;
+ m_installContext.locations->getConfigurationDir()) + L"/" + relativePath;
// get property data from packaged app
if (FileUtils::FileExists(absolutePath)) {
@@ -314,18 +322,8 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
}
DPL::String relativePath = pathPrefix + icon.src;
- DPL::String absolutePath;
-
- if (m_installContext.browserRequest) {
- // in case of browser installation
- size_t pos = m_installContext.widgetSource.rfind("/");
- absolutePath = DPL::FromUTF8String(
- m_installContext.widgetSource.substr(0, pos));
- } else {
- absolutePath = DPL::FromUTF8String(
- m_installContext.tempWidgetRoot);
- }
- absolutePath += L"/" + relativePath;
+ DPL::String absolutePath = DPL::FromUTF8String(
+ m_installContext.locations->getConfigurationDir()) + L"/" + relativePath;
if (FileUtils::FileExists(absolutePath)) {
DPL::String type = MimeTypeUtils::identifyFileMimeType(absolutePath);
@@ -633,5 +631,201 @@ bool TaskWidgetConfig::isTizenWebApp() const
return ret;
}
+bool TaskWidgetConfig::parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo,
+ const std::string& _currentPath, int* pErrCode)
+{
+ ParserRunner parser;
+ Try
+ {
+ parser.Parse(_currentPath, ElementParserPtr(new
+ RootParser<
+ WidgetParser>(
+ configInfo,
+ DPL::FromUTF32String(
+ L"widget"))));
+ }
+ Catch(ElementParser::Exception::Base)
+ {
+ LogDebug("Invalid widget configuration file!");
+ *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+ return false;
+ }
+ return true;
+}
+
+bool TaskWidgetConfig::parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo,
+ const std::string& _currentPath, int* pErrCode)
+{
+ ParserRunner parser;
+
+ //TODO: rewrite this madness
+ char cfgAbsPath[MAX_WIDGET_PATH_SIZE + 1] = { 0 };
+ DIR* dir = NULL;
+ struct dirent* ptr = NULL;
+
+ dir = opendir(_currentPath.c_str());
+ if (dir == NULL) {
+ *pErrCode = WRT_ERR_UNKNOWN;
+ return false;
+ }
+ bool has_config_xml = false;
+ errno = 0;
+ while ((ptr = readdir(dir)) != NULL) { //Find configuration file, based on its name
+ if (ptr->d_type == DT_REG) {
+ if (!strcmp(ptr->d_name, WRT_WIDGET_CONFIG_FILE_NAME)) {
+ _WrtUtilSetAbsolutePath(cfgAbsPath,
+ _currentPath.c_str(), ptr->d_name);
+ //Parse widget configuration file
+ LogDebug("Found config: " << cfgAbsPath);
+
+ Try
+ {
+ parser.Parse(cfgAbsPath, ElementParserPtr(new
+ RootParser<
+ WidgetParser>(
+ configInfo,
+ DPL
+ ::
+ FromUTF32String(
+ L"widget"))));
+ }
+ Catch(ElementParser::Exception::Base)
+ {
+ LogDebug("Invalid widget configuration file!");
+ // _rethrown_exception.Dump();
+ *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+ closedir(dir);
+ return false;
+ }
+
+ has_config_xml = true;
+ break;
+ }
+ }
+ }
+ closedir(dir);
+
+ //We must have config.xml so leaveing if we doesn't
+ if (!has_config_xml) {
+ LogDebug("Invalid archive");
+ *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+ return false;
+ }
+ return true;
+}
+
+bool TaskWidgetConfig::locateAndParseConfigurationFile(
+ const std::string& _currentPath,
+ WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
+ const std::string& baseFolder,
+ int* pErrCode)
+{
+ using namespace WrtDB;
+
+ if (!pErrCode) {
+ return false;
+ }
+
+ ConfigParserData& configInfo = pWidgetConfigInfo.configInfo;
+
+ // check if this installation from browser, or not.
+ size_t pos = _currentPath.rfind("/");
+ std::ostringstream infoPath;
+ infoPath << _currentPath.substr(pos+1);
+
+ std::string language = "";
+
+ if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) {
+ if (_currentPath.empty() || baseFolder.empty()) {
+ *pErrCode = WRT_ERR_INVALID_ARG;
+ return false;
+ }
+ // in case of general installation using wgt archive
+ if(!parseConfigurationFileWidget(configInfo, _currentPath, pErrCode))
+ {
+ return false;
+ }
+ } else {
+ // in case of browser installation
+ if(!parseConfigurationFileBrowser(configInfo, _currentPath, pErrCode))
+ {
+ return false;
+ }
+ }
+
+ char *tmp_language;
+ if (!_WrtUtilStringToLower(baseFolder.c_str(), &tmp_language)) {
+ *pErrCode = WRT_ERR_UNKNOWN;
+ return false;
+ }
+
+ if (!tmp_language) {
+ *pErrCode = WRT_ERR_UNKNOWN;
+ return false;
+ }
+ language = tmp_language;
+ free(tmp_language);
+
+ if(!fillWidgetConfig(pWidgetConfigInfo, configInfo))
+ {
+ *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+ return false;
+ }
+ return true;
+}
+
+bool TaskWidgetConfig::fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
+ WrtDB::ConfigParserData& configInfo)
+{
+ if (!!configInfo.widget_id) {
+ if (!pWidgetConfigInfo.guid) {
+ pWidgetConfigInfo.guid = configInfo.widget_id;
+ } else {
+ if (pWidgetConfigInfo.guid != configInfo.widget_id) {
+ LogDebug("Invalid archive");
+ return false;
+ }
+ }
+ }
+ if (!!configInfo.tizenId) {
+ if (!pWidgetConfigInfo.pkgname) {
+ pWidgetConfigInfo.pkgname = configInfo.tizenId;
+ } else {
+ if (pWidgetConfigInfo.pkgname != configInfo.tizenId) {
+ LogDebug("Invalid archive - Tizen ID not same error");
+ return false;
+ }
+ }
+ }
+ if (!!configInfo.version) {
+ if (!pWidgetConfigInfo.version) {
+ pWidgetConfigInfo.version = configInfo.version;
+ } else {
+ if (pWidgetConfigInfo.version != configInfo.version) {
+ LogDebug("Invalid archive");
+ return false;
+ }
+ }
+ }
+ if (!!configInfo.minVersionRequired) {
+ pWidgetConfigInfo.minVersion = configInfo.minVersionRequired;
+ } else if (!!configInfo.tizenMinVersionRequired) {
+ pWidgetConfigInfo.minVersion = configInfo.tizenMinVersionRequired;
+ }
+ return true;
+}
+
+void TaskWidgetConfig::processFile(const std::string& path,
+ WrtDB::WidgetRegisterInfo &widgetConfiguration)
+{
+ int pErrCode;
+
+ if (!locateAndParseConfigurationFile(path, widgetConfiguration,
+ DEFAULT_LANGUAGE, &pErrCode)) {
+ LogWarning("Widget archive: Failed while parsing config file");
+ ThrowMsg(Exception::ConfigParseFailed, path);
+ }
+}
+
} //namespace WidgetInstall
} //namespace Jobs
diff --git a/src/jobs/widget_install/task_widget_config.h b/src/jobs/widget_install/task_widget_config.h
index 12525a6..632128e 100755
--- a/src/jobs/widget_install/task_widget_config.h
+++ b/src/jobs/widget_install/task_widget_config.h
@@ -14,7 +14,7 @@
* limitations under the License.
*/
/*
- * @file task_widget_config.cpp
+ * @file task_widget_config.h
* @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
* @version 1.0
* @brief Implementation file for installer task widget config
@@ -22,13 +22,18 @@
#ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H
#define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H
-#include <WidgetConfigurationManager.h>
+#include <set>
+#include <list>
+
#include <dpl/task.h>
#include <dpl/task_list.h>
#include <dpl/string.h>
-#include <wrt_error.h>
+#include <dpl/optional.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
#include <dpl/wrt-dao-ro/global_config.h>
-#include <set>
+
+#include <wrt_error.h>
#include <wrt_common_types.h>
#include <widget_install/widget_install_popup.h>
@@ -49,6 +54,15 @@ class TaskWidgetConfig :
public WidgetInstallPopup
{
private:
+ class Exception
+ {
+ public:
+ DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, ConfigParseFailed)
+ };
+
+ typedef std::list<std::pair<DPL::String, DPL::String> > StringPairList;
+
InstallerContext& m_installContext;
WrtDB::LocaleSet m_localeFolders;
std::set<DPL::String> m_processedIconSet;
@@ -89,7 +103,26 @@ class TaskWidgetConfig :
bool isTizenWebApp() const;
bool parseVersionString(const std::string &version, long &majorVersion,
long &minorVersion, long &microVersion) const;
+ /**
+ * This method is used to process the config.xml of widget, get
+ * the corresponding configuration to pWidgetConfigInfo
+ *
+ * @param[in] path Specified the widget archive file path (absolute path).
+ * @return Configuration information of widget
+ */
+ void processFile(const std::string& path,
+ WrtDB::WidgetRegisterInfo &wConfig);
+ bool locateAndParseConfigurationFile(const std::string& currentPath,
+ WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
+ const std::string& baseFolder,
+ int* pErrCode);
+ bool parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo,
+ const std::string& _currentPath, int* pErrCode);
+ bool parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo,
+ const std::string& _currentPath, int* pErrCode);
+ bool fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
+ WrtDB::ConfigParserData& configInfo);
public:
TaskWidgetConfig(InstallerContext& installTaskContext);
};
diff --git a/src/jobs/widget_install/widget_install_context.h b/src/jobs/widget_install/widget_install_context.h
index 3716488..607505a 100755
--- a/src/jobs/widget_install/widget_install_context.h
+++ b/src/jobs/widget_install/widget_install_context.h
@@ -29,6 +29,7 @@
#include <widget_install/wac_security.h>
#include <feature_logic.h>
#include <widget_install/widget_update_info.h>
+#include <widget_location.h>
namespace Jobs {
namespace WidgetInstall {
@@ -85,12 +86,9 @@ struct InstallerContext
} InstallStep;
// Installation state variables
- std::string widgetSource; ///< Source widget zip file/widget url
- std::string tempWidgetPath; ///< Unpacked widget temporary path
- bool browserRequest; ///< Browser Request
- std::string installedIconPath; ///< Installed icon path
WrtDB::WidgetRegisterInfo widgetConfig; ///< WidgetConfigInfo
DPL::Optional<WrtDB::DbWidgetHandle> widgetHandle;
+ DPL::Optional<WidgetLocation> locations;
Jobs::WidgetInstall::WacSecurity wacSecurity;///< Widget Domain information.
InstallStep installStep; ///< current step of installation
Jobs::WidgetInstall::JobWidgetInstall *job;
@@ -107,9 +105,6 @@ struct InstallerContext
RequestedDevCapsMap staticPermittedDevCaps;
std::string installInfo; ///<For recovery>
bool m_quiet;
-
- std::string tempWidgetRoot; ///< temporary widget root path
- std::string installPath; ///< widget install path
};
#endif // INSTALLER_CONTEXT_H
diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.cpp b/src/jobs/widget_uninstall/job_widget_uninstall.cpp
index fb55919..9c6a0de 100644
--- a/src/jobs/widget_uninstall/job_widget_uninstall.cpp
+++ b/src/jobs/widget_uninstall/job_widget_uninstall.cpp
@@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <dpl/utils/file_utils.h>
+
#include <widget_uninstall/job_widget_uninstall.h>
#include <widget_uninstall/widget_uninstall_errors.h>
#include <widget_uninstall/task_check.h>
@@ -65,9 +68,12 @@ JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
m_context.job = this;
- Try {
+ Try
+ {
WrtDB::WidgetDAOReadOnly dao(widgetHandle);
m_context.pkgname = DPL::ToUTF8String(*dao.getPkgname());
+ m_context.locations = WidgetLocation(m_context.pkgname);
+
LogInfo("Widget model exists. Pkg name: " << m_context.pkgname);
AddTask(new TaskSmack(m_context));
@@ -85,7 +91,9 @@ JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
PKGMGR_START_KEY,
PKGMGR_START_UNINSTALL);
}
-
+ } Catch(FileUtils::CreateDirectoryException) {
+ LogError("Failed to create temporary path for widget");
+ AddTask(new UninstallerTaskFail(false));
} Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
AddTask(new UninstallerTaskFail(true));
} Catch (WidgetDAOReadOnly::Exception::Base) {
diff --git a/src/jobs/widget_uninstall/task_remove_files.cpp b/src/jobs/widget_uninstall/task_remove_files.cpp
index 8463b34..b747b7e 100644
--- a/src/jobs/widget_uninstall/task_remove_files.cpp
+++ b/src/jobs/widget_uninstall/task_remove_files.cpp
@@ -22,6 +22,7 @@
#include <widget_uninstall/task_remove_files.h>
#include <widget_uninstall/job_widget_uninstall.h>
+#include <widget_uninstall/uninstaller_context.h>
#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
#include <dpl/wrt-dao-ro/widget_config.h>
@@ -140,8 +141,7 @@ void TaskRemoveFiles::StepPrepare()
std::ostringstream widgetDir;
- widgetDir << GlobalConfig::GetUserInstalledWidgetPath() << "/";
- widgetDir << m_context.pkgname << "/";
+ widgetDir << m_context.locations->getPackageInstallationDir() << "/";
uninstRootDir = widgetDir.str();
ReadDir(uninstRootDir, filesList);
diff --git a/src/jobs/widget_uninstall/task_remove_files.h b/src/jobs/widget_uninstall/task_remove_files.h
index 902fac9..496bee9 100644
--- a/src/jobs/widget_uninstall/task_remove_files.h
+++ b/src/jobs/widget_uninstall/task_remove_files.h
@@ -23,9 +23,11 @@
#ifndef WRT_SRC_INSTALLER_CORE_JOB_WIDGET_UNINSTALL_TASK_REMOVE_FILES_H_
#define WRT_SRC_INSTALLER_CORE_JOB_WIDGET_UNINSTALL_TASK_REMOVE_FILES_H_
-#include <dpl/task.h>
+//forward declaration
+struct UninstallerContext;
-#include <widget_uninstall/uninstaller_context.h> //TODO forward decl
+#include <dpl/task.h>
+#include <dpl/log/log.h>
#include <string>
diff --git a/src/jobs/widget_uninstall/uninstaller_context.h b/src/jobs/widget_uninstall/uninstaller_context.h
index 2b65907..d6e9d52 100644
--- a/src/jobs/widget_uninstall/uninstaller_context.h
+++ b/src/jobs/widget_uninstall/uninstaller_context.h
@@ -25,6 +25,7 @@
#include <string>
#include <widget_uninstall/widget_uninstaller_struct.h>
+#include <widget_location.h>
namespace Jobs {
namespace WidgetUninstall {
@@ -57,6 +58,9 @@ struct UninstallerContext
///< flag that indicates whether installer finishes
//to remove files completely.
bool removeFinished;
+
+ DPL::Optional<WidgetLocation> locations;
+
UninstallStep uninstallStep; ///< current step of installation
Jobs::WidgetUninstall::JobWidgetUninstall *job;
std::string pkgname;