1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/step_remove_icons.h"
7 #include <boost/system/error_code.hpp>
8 #include <pkgmgr-info.h>
12 #include "common/backup_paths.h"
13 #include "common/utils/file_util.h"
14 #include "common/utils/glist_range.h"
16 namespace common_installer {
17 namespace filesystem {
19 namespace bs = boost::system;
20 namespace bf = boost::filesystem;
22 Step::Status StepRemoveIcons::precheck() {
23 if (!context_->manifest_data.get()) {
24 LOG(ERROR) << "manifest_data attribute is empty";
31 Step::Status StepRemoveIcons::process() {
32 for (application_x* app :
33 GListRange<application_x*>(context_->manifest_data.get()->application)) {
34 if (strcmp(app->component_type, "uiapp") != 0)
37 bf::path app_icon = bf::path(getIconPath(context_->uid.get()))
38 / bf::path(app->appid);
40 icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
41 app_icon += bf::path(icon->text).extension();
45 if (bf::exists(app_icon)) {
46 bf::path backup_icon_file = GetBackupPathForIconFile(app_icon);
47 if (!MoveFile(app_icon, backup_icon_file)) {
48 LOG(ERROR) << "Failed to create backup for icon: " << app_icon;
51 backups_.emplace_back(backup_icon_file, app_icon);
57 Step::Status StepRemoveIcons::clean() {
59 if (!backups_.empty()) {
60 LOG(DEBUG) << "Clean up icons files...";
61 for (auto& pair : backups_) {
62 bf::remove(pair.first, error);
64 LOG(WARNING) << "Failed to remove: " << pair.first;
71 Step::Status StepRemoveIcons::undo() {
72 Step::Status ret = Status::OK;
73 if (!backups_.empty()) {
74 LOG(DEBUG) << "Restoring icons files...";
75 for (auto& pair : backups_) {
76 if (!MoveFile(pair.first, pair.second)) {
77 LOG(ERROR) << "Failed to restore: " << pair.second;
78 // We need to try to restore all icons anyway...
85 } // namespace filesystem
86 } // namespace common_installer