summaryrefslogtreecommitdiff
path: root/src/jobs/widget_install/task_file_manipulation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/jobs/widget_install/task_file_manipulation.cpp')
-rw-r--r--src/jobs/widget_install/task_file_manipulation.cpp129
1 files changed, 129 insertions, 0 deletions
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