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 StepBackupIcons::StepBackupIcons(InstallerContext* context) : Step(context),
25 extra_icon_path_(nullptr) {}
27 Step::Status StepBackupIcons::process() {
28 extra_icon_path_ = getIconPath(context_->uid.get(),
29 context_->is_readonly_package.get());
30 if (!extra_icon_path_)
36 return Status::ICON_ERROR;
38 LOG(DEBUG) << "Icons backup created";
42 Step::Status StepBackupIcons::clean() {
44 LOG(DEBUG) << "Icons backup removed";
49 Step::Status StepBackupIcons::undo() {
50 for (auto& pair : icons_) {
51 if (!MoveFile(pair.second, pair.first)) {
52 LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
53 return Status::ICON_ERROR;
56 LOG(DEBUG) << "Icons reverted from backup";
61 bool StepBackupIcons::BackupIcons() {
62 for (auto& pair : icons_) {
63 if (!MoveFile(pair.first, pair.second, true)) {
64 LOG(ERROR) << "Cannot create backup for icon: " << pair.first;
72 void StepBackupIcons::RemoveBackupIcons() {
73 for (auto& pair : icons_)
77 void StepBackupIcons::GetIconInfo() {
78 for (auto iter = bf::directory_iterator(extra_icon_path_);
79 iter != bf::directory_iterator(); ++iter) {
80 if (!bf::is_regular_file(iter->path()))
83 AddAppIconToList(iter->path());
87 void StepBackupIcons::AddAppIconToList(boost::filesystem::path path) {
88 for (application_x* app : GListRange<application_x*>(
89 context_->old_manifest_data.get()->application)) {
93 bf::path filename = path.filename();
94 filename.replace_extension();
95 std::string id = filename.string();
96 if (id == app->appid) {
97 bf::path icon_backup = GetBackupPathForIconFile(path);
98 icons_.emplace_back(path, icon_backup);
103 } // namespace backup
104 } // namespace common_installer