Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_remove_icons.cc
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.
4
5 #include "common/step/filesystem/step_remove_icons.h"
6
7 #include <pkgmgr-info.h>
8
9 #include <cstring>
10 #include <filesystem>
11 #include <string>
12 #include <system_error>
13
14 #include "common/utils/file_util.h"
15 #include "common/utils/glist_range.h"
16
17 namespace fs = std::filesystem;
18
19 namespace common_installer {
20 namespace filesystem {
21
22 Step::Status StepRemoveIcons::precheck() {
23   if (!context_->manifest_data.get()) {
24     LOG(ERROR) << "manifest_data attribute is empty";
25     return Status::MANIFEST_NOT_FOUND;
26   }
27
28   return Status::OK;
29 }
30
31 Step::Status StepRemoveIcons::process() {
32   const char* extra_icon_path = getIconPath(context_->uid.get(),
33       context_->is_readonly_package.get());
34   if (!extra_icon_path)
35     return Status::OK;
36   for (auto iter = fs::directory_iterator(extra_icon_path);
37       iter != fs::directory_iterator(); ++iter) {
38     if (!fs::is_regular_file(iter->path()))
39       continue;
40     std::error_code error;
41     for (application_x* app :
42         GListRange<application_x*>(
43            context_->manifest_data.get()->application)) {
44       if (app->icon) {
45         std::string filename = iter->path().filename().string();
46         if (filename.find(app->appid) == 0) {
47           Remove(iter->path());
48         }
49       }
50     }
51   }
52   return Status::OK;
53 }
54
55 }  // namespace filesystem
56 }  // namespace common_installer