2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file task_db_update.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
20 * @brief Implementation file for installer task database updating
23 #include <widget_install/task_file_manipulation.h>
24 #include <widget_install/job_widget_install.h>
25 #include <widget_install/widget_install_errors.h>
26 #include <widget_install/widget_install_context.h>
27 #include <dpl/utils/wrt_utility.h>
28 #include <dpl/foreach.h>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
33 using namespace WrtDB;
36 namespace WidgetInstall {
37 TaskFileManipulation::TaskFileManipulation(InstallerContext& context) :
38 DPL::TaskDecl<TaskFileManipulation>(this),
41 AddStep(&TaskFileManipulation::StepCreateDirs);
42 AddStep(&TaskFileManipulation::StepRenamePath);
44 AddAbortStep(&TaskFileManipulation::StepAbortRenamePath);
47 void TaskFileManipulation::StepCreateDirs()
49 std::string widgetPath;
50 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
51 if (pkgname.IsNull()) {
52 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
55 widgetPath = m_context.locations->getPackageInstallationDir();
57 std::string widgetBinPath = m_context.locations->getBinaryDir();
58 std::string widgetSrcPath = m_context.locations->getSourceDir();
60 _WrtMakeDir(widgetPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
62 // If package type is widget with osp service, we don't need to make bin
64 if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
65 LogDebug("Doesn't need to create resource directory");
67 LogDebug("Create resource directory");
68 _WrtMakeDir(widgetBinPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
69 _WrtMakeDir(widgetSrcPath.c_str(), 0755, WRT_FILEUTILS_RECUR);
72 m_context.job->UpdateProgress(
73 InstallerContext::INSTALL_DIR_CREATE,
74 "Widget Directory Created");
77 void TaskFileManipulation::StepRenamePath()
80 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
81 if (pkgname.IsNull()) {
82 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
85 if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
86 instDir = m_context.locations->getPackageInstallationDir();
88 instDir = m_context.locations->getSourceDir();
91 LogDebug("Copy file from temp directory to " << instDir);
92 if (!_WrtUtilRemoveDir(instDir.c_str())) {
93 ThrowMsg(Exceptions::RemovingFolderFailure,
94 "Error occurs during removing existing folder");
97 if (!(rename(m_context.locations->getTemporaryPackageDir().c_str(), instDir.c_str()) == 0)) {
98 ThrowMsg(Exceptions::UnknownError,
99 "Error occurs during renaming widget folder");
102 m_context.job->UpdateProgress(
103 InstallerContext::INSTALL_RENAME_PATH,
104 "Widget Rename path Finished");
107 void TaskFileManipulation::StepAbortRenamePath()
109 LogDebug("[Rename Widget Path] Aborting.... (Rename path)");
110 Assert(!!m_context.widgetHandle);
111 std::string widgetPath;
112 if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) {
113 widgetPath = m_context.locations->getPackageInstallationDir();
115 widgetPath = m_context.locations->getSourceDir();
117 struct stat fileInfo;
118 if (stat(widgetPath.c_str(), &fileInfo) != 0) {
119 LogError("Failed to get widget file path : " << widgetPath);
123 if (!(rename(widgetPath.c_str(), m_context.locations->getTemporaryPackageDir().c_str()) == 0)) {
124 LogError("Failed to rename");
126 LogDebug("Rename widget path sucessful!");
128 } //namespace WidgetInstall