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_update_files.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
20 * @brief Implementation file for installer task update files
31 #include <widget_install/task_update_files.h>
32 #include <dpl/assert.h>
33 #include <dpl/foreach.h>
34 #include <dpl/utils/wrt_utility.h>
36 #include <widget_install/widget_install_context.h>
37 #include <widget_install/widget_install_errors.h>
38 #include <widget_install/job_widget_install.h>
39 #include <widget_install/directory_api.h>
41 #include <dpl/wrt-dao-ro/global_config.h>
42 #include <dpl/exception.h>
43 #include <dpl/errno_string.h>
45 #include <installer_log.h>
47 using namespace WrtDB;
50 inline const char* GetWidgetBackupDirPath()
57 namespace WidgetInstall {
58 TaskUpdateFiles::TaskUpdateFiles(InstallerContext& context) :
59 DPL::TaskDecl<TaskUpdateFiles>(this),
62 AddStep(&TaskUpdateFiles::StartStep);
63 AddStep(&TaskUpdateFiles::StepBackupDirectory);
64 AddStep(&TaskUpdateFiles::EndStep);
66 AddAbortStep(&TaskUpdateFiles::StepAbortBackupDirectory);
69 void TaskUpdateFiles::StepBackupDirectory()
71 _D("StepCreateBackupFolder");
73 std::string backPath = m_context.locations->getBackupDir();
74 _D("Backup resource directory path : %s", backPath.c_str());
75 std::string pkgPath = m_context.locations->getPackageInstallationDir();
77 if (0 == access(backPath.c_str(), F_OK)) {
78 if (!WrtUtilRemove(backPath)) {
79 ThrowMsg(Exceptions::RemovingFolderFailure,
80 "Error occurs during removing backup resource directory");
83 _D("copy : %s to %s", pkgPath.c_str(), backPath.c_str());
84 if ((rename(pkgPath.c_str(), backPath.c_str())) != 0) {
85 _E("Failed to rename %s to %s", pkgPath.c_str(), backPath.c_str());
86 ThrowMsg(Exceptions::BackupFailed,
87 "Error occurs during rename file");
90 WrtUtilMakeDir(pkgPath);
93 void TaskUpdateFiles::StepAbortBackupDirectory()
95 _D("StepAbortCopyFiles");
97 std::string backPath = m_context.locations->getBackupDir();
98 std::string pkgPath = m_context.locations->getPackageInstallationDir();
100 _D("Backup Folder %s to %s", backPath.c_str(), pkgPath.c_str());
102 if (!WrtUtilRemove(pkgPath)) {
103 _E("Failed to remove %s", pkgPath.c_str());
106 if (rename(backPath.c_str(), pkgPath.c_str()) != 0) {
107 _E("Failed to rename %s to %s", backPath.c_str(), pkgPath.c_str());
111 void TaskUpdateFiles::StartStep()
113 _D("--------- <TaskUpdateFiles> : START ----------");
116 void TaskUpdateFiles::EndStep()
118 m_context.job->UpdateProgress(
119 InstallerContext::INSTALL_CREATE_BACKUP_DIR,
120 "Backup directory created for update");
122 _D("--------- <TaskUpdateFiles> : END ----------");
124 } //namespace WidgetInstall