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>
12 #include "common/utils/paths.h"
13 #include "common/utils/file_util.h"
14 #include "common/utils/glist_range.h"
16 namespace fs = std::filesystem;
18 namespace common_installer {
21 StepBackupIcons::StepBackupIcons(InstallerContext* context) : Step(context),
22 extra_icon_path_(nullptr) {}
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 = fs::directory_iterator(extra_icon_path_);
76 iter != fs::directory_iterator(); ++iter) {
77 if (!fs::is_regular_file(iter->path()))
80 AddAppIconToList(iter->path());
84 void StepBackupIcons::AddAppIconToList(std::filesystem::path path) {
85 for (application_x* app : GListRange<application_x*>(
86 context_->old_manifest_data.get()->application)) {
90 fs::path filename = path.filename();
91 filename.replace_extension();
92 std::string id = filename.string();
93 if (id == app->appid) {
94 fs::path icon_backup = GetBackupPathForIconFile(path);
95 icons_.emplace_back(path, icon_backup);
100 } // namespace backup
101 } // namespace common_installer