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/log/log.h>
34 #include <dpl/foreach.h>
35 #include <dpl/utils/wrt_utility.h>
37 #include <widget_install/widget_install_context.h>
38 #include <widget_install/widget_install_errors.h>
39 #include <widget_install/job_widget_install.h>
40 #include <widget_install/directory_api.h>
42 #include <dpl/wrt-dao-ro/global_config.h>
43 #include <dpl/exception.h>
44 #include <dpl/errno_string.h>
46 using namespace WrtDB;
49 inline const char* GetWidgetBackupDirPath()
56 namespace WidgetInstall {
57 TaskUpdateFiles::TaskUpdateFiles(InstallerContext& context) :
58 DPL::TaskDecl<TaskUpdateFiles>(this),
61 AddStep(&TaskUpdateFiles::StartStep);
62 AddStep(&TaskUpdateFiles::StepBackupDirectory);
63 AddStep(&TaskUpdateFiles::EndStep);
65 AddAbortStep(&TaskUpdateFiles::StepAbortBackupDirectory);
68 void TaskUpdateFiles::StepBackupDirectory()
70 LogDebug("StepCreateBackupFolder");
72 std::string backPath = m_context.locations->getBackupDir();
73 LogDebug("Backup resource directory path : " << backPath);
74 std::string pkgPath = m_context.locations->getPackageInstallationDir();
76 if (0 == access(backPath.c_str(), F_OK)) {
77 if (!WrtUtilRemove(backPath)) {
78 ThrowMsg(Exceptions::RemovingFolderFailure,
79 "Error occurs during removing backup resource directory");
82 LogDebug("copy : " << pkgPath << " to " << backPath);
83 if ((rename(pkgPath.c_str(), backPath.c_str())) != 0) {
84 LogError("Failed to rename " << pkgPath << " to " << backPath);
85 ThrowMsg(Exceptions::BackupFailed,
86 "Error occurs during rename file");
89 WrtUtilMakeDir(pkgPath);
92 void TaskUpdateFiles::StepAbortBackupDirectory()
94 LogDebug("StepAbortCopyFiles");
96 std::string backPath = m_context.locations->getBackupDir();
97 std::string pkgPath = m_context.locations->getPackageInstallationDir();
99 LogDebug("Backup Folder " << backPath << " to " << pkgPath);
101 if (!WrtUtilRemove(pkgPath)) {
102 LogError("Failed to remove " << pkgPath);
105 if (rename(backPath.c_str(), pkgPath.c_str()) != 0) {
106 LogError("Failed to rename " << backPath << " to " << pkgPath);
110 void TaskUpdateFiles::StartStep()
112 LogDebug("--------- <TaskUpdateFiles> : START ----------");
115 void TaskUpdateFiles::EndStep()
117 m_context.job->UpdateProgress(
118 InstallerContext::INSTALL_CREATE_BACKUP_DIR,
119 "Backup directory created for update");
121 LogDebug("--------- <TaskUpdateFiles> : END ----------");
123 } //namespace WidgetInstall