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 <boost/filesystem/operations.hpp>
8 #include <boost/system/error_code.hpp>
9 #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 bf = boost::filesystem;
16 namespace bs = boost::system;
18 namespace common_installer {
19 namespace filesystem {
21 Step::Status StepRecoverIcons::RecoveryNew() {
22 if (!TryGatherIcons()) {
23 LOG(DEBUG) << "Icons recovery not needed";
26 for (auto& pair : icons_) {
29 LOG(INFO) << "Icons recovery done";
33 Step::Status StepRecoverIcons::RecoveryUpdate() {
34 if (!TryGatherIcons()) {
35 LOG(DEBUG) << "Icons recovery not needed";
38 for (auto& pair : icons_) {
39 if (bf::exists(pair.second)) {
40 if (!Remove(pair.first)) {
41 LOG(ERROR) << "Cannot move icon to restore its correct location";
42 return Status::RECOVERY_ERROR;
45 (void) MoveFile(pair.second, pair.first);
47 LOG(INFO) << "Icons recovery done";
51 bool StepRecoverIcons::TryGatherIcons() {
52 if (!context_->manifest_data.get())
56 const char* extra_icon_path = getIconPath(context_->uid.get(),
57 context_->is_readonly_package.get());
60 for (auto iter = bf::directory_iterator(extra_icon_path);
61 iter != bf::directory_iterator(); ++iter) {
62 if (!bf::is_regular_file(iter->path()))
64 for (application_x* app : GListRange<application_x*>(
65 context_->manifest_data.get()->application)) {
67 bf::path p = iter->path();
68 std::string filename = iter->path().filename().string();
69 if (filename.find(app->appid) == 0) {
72 if (p.extension() == GetIconFileBackupExtension()) {
74 icon = p.replace_extension("");
77 icon_backup = GetBackupPathForIconFile(iter->path());
79 icons_.insert(std::make_pair(icon, icon_backup));
87 } // namespace filesystem
88 } // namespace common_installer