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/filesystem/step_recover_icons.h"
7 #include <pkgmgr-info.h>
11 #include "common/utils/paths.h"
12 #include "common/utils/file_util.h"
13 #include "common/utils/glist_range.h"
15 namespace fs = std::filesystem;
17 namespace common_installer {
18 namespace filesystem {
20 Step::Status StepRecoverIcons::RecoveryNew() {
21 if (!TryGatherIcons()) {
22 LOG(DEBUG) << "Icons recovery not needed";
25 for (auto& pair : icons_) {
28 LOG(INFO) << "Icons recovery done";
32 Step::Status StepRecoverIcons::RecoveryUpdate() {
33 if (!TryGatherIcons()) {
34 LOG(DEBUG) << "Icons recovery not needed";
37 for (auto& pair : icons_) {
38 if (fs::exists(pair.second)) {
39 if (!Remove(pair.first)) {
40 LOG(ERROR) << "Cannot move icon to restore its correct location";
41 return Status::RECOVERY_ERROR;
44 (void) MoveFile(pair.second, pair.first);
46 LOG(INFO) << "Icons recovery done";
50 bool StepRecoverIcons::TryGatherIcons() {
51 if (!context_->manifest_data.get())
55 const char* extra_icon_path = getIconPath(context_->uid.get(),
56 context_->is_readonly_package.get());
59 for (auto iter = fs::directory_iterator(extra_icon_path);
60 iter != fs::directory_iterator(); ++iter) {
61 if (!fs::is_regular_file(iter->path()))
63 for (application_x* app : GListRange<application_x*>(
64 context_->manifest_data.get()->application)) {
66 fs::path p = iter->path();
67 std::string filename = iter->path().filename().string();
68 if (filename.find(app->appid) == 0) {
71 if (p.extension() == GetIconFileBackupExtension()) {
73 icon = p.replace_extension("");
76 icon_backup = GetBackupPathForIconFile(iter->path());
78 icons_.insert(std::make_pair(icon, icon_backup));
86 } // namespace filesystem
87 } // namespace common_installer