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::StepBackupDirectory);
63 AddAbortStep(&TaskUpdateFiles::StepAbortBackupDirectory);
66 void TaskUpdateFiles::StepBackupDirectory()
68 LogDebug("StepCreateBackupFolder");
70 std::string backPath = m_context.locations->getBackupDir();
71 LogDebug("backup resource directory path : " << backPath);
72 std::string pkgPath = m_context.locations->getPackageInstallationDir();
74 if (0 == access(backPath.c_str(), F_OK)) {
75 WrtUtilRemove(backPath);
77 LogDebug("copy : " << pkgPath << " to " << backPath);
78 if ((rename(pkgPath.c_str(), backPath.c_str())) != 0) {
79 LogError("Failed to rename " << pkgPath << " to " << backPath);
80 ThrowMsg(Exceptions::BackupFailed,
81 "Error occurs during rename file");
84 WrtUtilMakeDir(pkgPath);
86 m_context.job->UpdateProgress(
87 InstallerContext::INSTALL_CREATE_BACKUP_DIR,
88 "Backup directory created for update");
91 void TaskUpdateFiles::StepAbortBackupDirectory()
93 LogDebug("StepAbortCopyFiles");
95 std::string backPath = m_context.locations->getBackupDir();
96 std::string pkgPath = m_context.locations->getPackageInstallationDir();
98 LogDebug("Backup Folder " << backPath << " to " << pkgPath);
100 if (!WrtUtilRemove(pkgPath)) {
101 LogError("Failed to remove " << pkgPath);
104 if (rename(backPath.c_str(), pkgPath.c_str()) != 0) {
105 LogError("Failed to rename " << backPath << " to " << pkgPath);
108 } //namespace WidgetInstall