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

mendersoftware / mender / 2271300743

19 Jan 2026 11:42AM UTC coverage: 81.376% (+1.7%) from 79.701%
2271300743

push

gitlab-ci

web-flow
Merge pull request #1879 from lluiscampos/MEN-8687-ci-debian-updates

MEN-8687: Update Debian base images for CI jobs

8791 of 10803 relevant lines covered (81.38%)

20310.08 hits per line

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

83.33
/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
        try {
42
                fs::path dir_path(generators_dir);
11✔
43
                if (!fs::exists(dir_path)) {
11✔
44
                        return kvp::ExpectedKeyValuesMap(data);
×
45
                }
46

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

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

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

64
                        fs::perms perms = entry.status().permissions();
65
                        if ((perms & (fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec))
16✔
66
                                == fs::perms::none) {
67
                                log::Warning("'" + file_path_str + "' is not executable");
1✔
68
                                continue;
1✔
69
                        }
70
                        procs::Process proc({file_path_str});
30✔
71
                        auto ex_line_data = proc.GenerateLineData();
15✔
72
                        if (!ex_line_data) {
15✔
73
                                log::Error("'" + file_path_str + "' failed: " + ex_line_data.error().message);
×
74
                                any_failure = true;
75
                                continue;
76
                        }
77

78
                        auto err = kvp::AddParseKeyValues(data, ex_line_data.value());
15✔
79
                        if (error::NoError != err) {
15✔
80
                                log::Error("Failed to parse data from '" + file_path_str + "': " + err.message);
8✔
81
                                any_failure = true;
82
                        } else {
83
                                any_success = true;
84
                        }
85
                }
32✔
86

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

101
} // namespace inventory_parser
102
} // namespace client_shared
103
} // 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