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/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_) {
28 bf::remove(pair.first, error);
30 LOG(INFO) << "Icons recovery done";
34 Step::Status StepRecoverIcons::RecoveryUpdate() {
35 if (!TryGatherIcons()) {
36 LOG(DEBUG) << "Icons recovery not needed";
39 for (auto& pair : icons_) {
40 if (bf::exists(pair.first)) {
42 bf::remove(pair.first, error);
44 LOG(ERROR) << "Cannot move icon to restore its correct location";
45 return Status::RECOVERY_ERROR;
48 (void) MoveFile(pair.second, pair.first);
50 LOG(INFO) << "Icons recovery done";
54 bool StepRecoverIcons::TryGatherIcons() {
55 if (!context_->manifest_data.get())
59 const char* extra_icon_path = getIconPath(context_->uid.get(),
60 context_->is_preload_request.get());
63 for (auto iter = bf::directory_iterator(extra_icon_path);
64 iter != bf::directory_iterator(); ++iter) {
65 if (!bf::is_regular_file(iter->path()))
67 for (application_x* app : GListRange<application_x*>(
68 context_->manifest_data.get()->application)) {
70 bf::path p = iter->path();
71 std::string filename = iter->path().filename().string();
72 if (filename.find(app->appid) == 0) {
75 if (p.extension() == GetIconFileBackupExtension()) {
77 icon = p.replace_extension("");
80 icon_backup = GetBackupPathForIconFile(iter->path());
82 icons_.insert(std::make_pair(icon, icon_backup));
90 } // namespace filesystem
91 } // namespace common_installer