WidgetHandle removal - part 2. Task order change
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_remove_backup.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_remove_backup.cpp
18  * @author  Soyoung kim(sy037.kim@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task backup files remove
21  */
22 #include <widget_install/task_remove_backup.h>
23
24 #include <sys/stat.h>
25 #include <string>
26 #include <sstream>
27 #include <dpl/wrt-dao-ro/global_config.h>
28 #include <dpl/foreach.h>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
31 #include <dpl/utils/wrt_utility.h>
32 #include <widget_install/job_widget_install.h>
33 #include <widget_install/widget_install_errors.h>
34 #include <widget_install/widget_install_context.h>
35
36 using namespace WrtDB;
37
38 namespace Jobs {
39 namespace WidgetInstall {
40 TaskRemoveBackupFiles::TaskRemoveBackupFiles(InstallerContext& context) :
41     DPL::TaskDecl<TaskRemoveBackupFiles>(this),
42     m_context(context)
43 {
44     AddStep(&TaskRemoveBackupFiles::StepRemoveBackupFiles);
45 }
46
47 void TaskRemoveBackupFiles::StepRemoveBackupFiles()
48 {
49     std::ostringstream backupDir;
50     backupDir << m_context.locations->getBackupDir();
51
52     if (WrtUtilRemove(backupDir.str())) {
53         LogDebug("Success to remove backup files : " << backupDir.str());
54     } else {
55         LogError("Failed to remove backup directory : " << backupDir.str());
56         ThrowMsg(Exceptions::RemoveBackupFailed,
57                  "Error occurs during removing existing folder");
58     }
59
60     std::string tmp = m_context.locations->getTemporaryPackageDir();
61     if (WrtUtilRemove(tmp)) {
62         LogDebug("Success to remove temp directory : " << tmp);
63     } else {
64         LogError("Failed to remove temp directory : " << tmp);
65         ThrowMsg(Exceptions::RemoveBackupFailed,
66                  "Error occurs during removing existing folder");
67     }
68
69     m_context.job->UpdateProgress(
70         InstallerContext::INSTALL_REMOVE_BACKUP_FILE,
71         "Backup widget file delete Finished");
72 }
73
74 } //namespace WidgetInstall
75 } //namespace Jobs