1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/backup/step_backup_icons.h"
7 #include <pkgmgr-info.h>
9 #include <boost/filesystem.hpp>
10 #include <boost/system/error_code.hpp>
14 #include "common/utils/paths.h"
15 #include "common/utils/file_util.h"
16 #include "common/utils/glist_range.h"
18 namespace bf = boost::filesystem;
19 namespace bs = boost::system;
21 namespace common_installer {
24 Step::Status StepBackupIcons::process() {
25 extra_icon_path_ = getIconPath(context_->uid.get(),
26 context_->is_readonly_package.get());
27 if (!extra_icon_path_)
33 return Status::ICON_ERROR;
35 LOG(DEBUG) << "Icons backup created";
39 Step::Status StepBackupIcons::clean() {
41 LOG(DEBUG) << "Icons backup removed";
46 Step::Status StepBackupIcons::undo() {
47 for (auto& pair : icons_) {
48 if (!MoveFile(pair.second, pair.first)) {
49 LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
50 return Status::ICON_ERROR;
53 LOG(DEBUG) << "Icons reverted from backup";
58 bool StepBackupIcons::BackupIcons() {
59 for (auto& pair : icons_) {
60 if (!MoveFile(pair.first, pair.second, true)) {
61 LOG(ERROR) << "Cannot create backup for icon: " << pair.first;
69 void StepBackupIcons::RemoveBackupIcons() {
70 for (auto& pair : icons_)
74 void StepBackupIcons::GetIconInfo() {
75 for (auto iter = bf::directory_iterator(extra_icon_path_);
76 iter != bf::directory_iterator(); ++iter) {
77 if (!bf::is_regular_file(iter->path()))
80 AddAppIconToList(iter->path());
84 void StepBackupIcons::AddAppIconToList(boost::filesystem::path path) {
85 for (application_x* app : GListRange<application_x*>(
86 context_->old_manifest_data.get()->application)) {
90 bf::path filename = path.filename();
91 filename.replace_extension();
92 std::string id = filename.string();
93 if (id == app->appid) {
94 bf::path icon_backup = GetBackupPathForIconFile(path);
95 icons_.emplace_back(path, icon_backup);
100 } // namespace backup
101 } // namespace common_installer