• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 2507159399

07 May 2026 11:23AM UTC coverage: 81.702% (+0.02%) from 81.686%
2507159399

push

gitlab-ci

web-flow
Merge pull request #1947 from mendersoftware/cherry-5.1.x-master-base_cpp_image

[Cherry 5.1.x]: Miscellaneous CI improvements

6 of 7 new or added lines in 1 file covered. (85.71%)

9064 of 11094 relevant lines covered (81.7%)

20573.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/src/client_shared/inventory_parser/platform/c++17/inventory_parser.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <client_shared/inventory_parser.hpp>
16

17
#include <filesystem>
18

19
#include <common/expected.hpp>
20
#include <common/key_value_parser.hpp>
21
#include <common/processes.hpp>
22
#include <common/log.hpp>
23

24
namespace mender {
25
namespace client_shared {
26
namespace inventory_parser {
27

28
using namespace std;
29
namespace expected = mender::common::expected;
30
namespace kvp = mender::common::key_value_parser;
31
namespace procs = mender::common::processes;
32
namespace log = mender::common::log;
33
namespace error = mender::common::error;
34
namespace fs = std::filesystem;
35

36
kvp::ExpectedKeyValuesMap GetInventoryData(const string &generators_dir) {
11✔
37
        bool any_success = false;
38
        bool any_failure = false;
39
        kvp::KeyValuesMap data;
40

41
        vector<string> scripts;
42
        try {
43
                fs::path dir_path(generators_dir);
11✔
44
                if (!fs::exists(dir_path)) {
11✔
45
                        return kvp::ExpectedKeyValuesMap(data);
×
46
                }
47

48
                for (const auto &entry : fs::directory_iterator {dir_path}) {
50✔
49
                        fs::path file_path = entry.path();
17✔
50
                        if (!fs::is_regular_file(file_path)) {
17✔
51
                                continue;
×
52
                        }
53

54
                        string file_path_str = file_path.string();
17✔
55
                        string file_name = file_path.filename().string();
17✔
56
                        if (file_name.find("mender-inventory-") != 0) {
17✔
57
                                log::Warning(
1✔
58
                                        "'" + file_path_str
1✔
59
                                        + "' doesn't have the 'mender-inventory-' prefix, skipping");
1✔
60
                                continue;
1✔
61
                        }
62

63
                        log::Debug("Found inventory script: " + file_name);
32✔
64

65
                        fs::perms perms = entry.status().permissions();
66
                        if ((perms & (fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec))
16✔
67
                                == fs::perms::none) {
68
                                log::Warning("'" + file_path_str + "' is not executable");
1✔
69
                                continue;
1✔
70
                        }
71
                        scripts.emplace_back(std::move(file_path_str));
15✔
72
                }
17✔
73
                std::sort(scripts.begin(), scripts.end());
11✔
74

75
                for (const auto &script_path : scripts) {
26✔
76
                        procs::Process proc({script_path});
30✔
77
                        auto ex_line_data = proc.GenerateLineData();
15✔
78
                        if (!ex_line_data) {
15✔
NEW
79
                                log::Error("'" + script_path + "' failed: " + ex_line_data.error().message);
×
80
                                any_failure = true;
81
                                continue;
82
                        }
83

84
                        auto err = kvp::AddParseKeyValues(data, ex_line_data.value());
15✔
85
                        if (error::NoError != err) {
15✔
86
                                log::Error("Failed to parse data from '" + script_path + "': " + err.message);
8✔
87
                                any_failure = true;
88
                        } else {
89
                                any_success = true;
90
                        }
91
                }
15✔
92

93
                if (any_success || !any_failure) {
11✔
94
                        return kvp::ExpectedKeyValuesMap(data);
10✔
95
                } else {
96
                        error::Error error = MakeError(
97
                                kvp::KeyValueParserErrorCode::NoDataError,
98
                                "No data successfully read from inventory scripts in '" + generators_dir + "'");
2✔
99
                        return expected::unexpected(error);
2✔
100
                }
101
        } catch (const fs::filesystem_error &e) {
11✔
102
                return expected::unexpected(
×
103
                        error::Error(e.code().default_error_condition(), "Failure while parsing inventory"));
×
104
        }
×
105
}
26✔
106

107
} // namespace inventory_parser
108
} // namespace client_shared
109
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc