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

mendersoftware / mender / 1022567176

02 Oct 2023 07:50AM UTC coverage: 80.127% (+2.5%) from 77.645%
1022567176

push

gitlab-ci

kacf
chore: Centralize selection of `std::filesystem` library.

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

6447 of 8046 relevant lines covered (80.13%)

9912.21 hits per line

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

50.0
/mender-update/context.hpp
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
#ifndef MENDER_COMMON_CONTEXT_HPP
16
#define MENDER_COMMON_CONTEXT_HPP
17

18
#include <string>
19
#include <unordered_map>
20

21
#include <artifact/artifact.hpp>
22
#include <common/conf.hpp>
23
#include <common/error.hpp>
24
#include <common/expected.hpp>
25
#include <common/key_value_database.hpp>
26
#include <common/optional.hpp>
27

28
#if MENDER_USE_LMDB
29
#include <common/key_value_database_lmdb.hpp>
30
#else
31
#error MenderContext requires LMDB
32
#endif // MENDER_USE_LMDB
33

34
namespace mender {
35
namespace update {
36
namespace context {
37

38
namespace artifact = mender::artifact;
39
namespace conf = mender::common::conf;
40
namespace error = mender::common::error;
41
namespace expected = mender::common::expected;
42
namespace kv_db = mender::common::key_value_database;
43

44
using namespace std;
45

46
enum MenderContextErrorCode {
47
        NoError = 0,
48
        ParseError,
49
        ValueError,
50
        NoSuchUpdateModuleError,
51
        DatabaseValueError,
52
        RebootRequiredError,
53
        NoUpdateInProgressError,
54
        UnexpectedHttpResponse,
55
        StateDataStoreCountExceededError,
56
};
57

58
class MenderContextErrorCategoryClass : public std::error_category {
59
public:
60
        const char *name() const noexcept override;
61
        string message(int code) const override;
62
};
63
extern const MenderContextErrorCategoryClass MenderContextErrorCategory;
64

65
error::Error MakeError(MenderContextErrorCode code, const string &msg);
66

67
using ProvidesData = unordered_map<string, string>;
68
using ClearsProvidesData = vector<string>;
69
using ExpectedProvidesData = expected::expected<ProvidesData, error::Error>;
70

71
class MenderContext {
72
public:
73
        MenderContext(conf::MenderConfig &config) :
28✔
74
                config_ {config} {};
28✔
75
        virtual ~MenderContext() {
×
76
        }
×
77

78
        error::Error Initialize();
79
        virtual kv_db::KeyValueDatabase &GetMenderStoreDB();
80
        ExpectedProvidesData LoadProvides();
81
        ExpectedProvidesData LoadProvides(kv_db::Transaction &txn);
82
        expected::ExpectedString GetDeviceType();
83
        // Stores new artifact data, taking existing provides, and clears_provides, into account.
84
        error::Error CommitArtifactData(
85
                string artifact_name,
86
                string artifact_group,
87
                const optional<ProvidesData> &new_provides,
88
                const optional<ClearsProvidesData> &clears_provides,
89
                function<error::Error(kv_db::Transaction &)> txn_func);
90
        conf::MenderConfig &GetConfig() {
91
                return config_;
92
        }
93

94
        expected::ExpectedBool MatchesArtifactDepends(const artifact::HeaderView &hdr_view);
95

96
        // Suffix used for updates that either can't roll back or fail their rollback.
97
        static const string broken_artifact_name_suffix;
98

99
        // DATABASE KEYS ------------------------------------------------------
100

101
        // Name of artifact currently installed. Introduced in Mender 2.0.0.
102
        static const string artifact_name_key;
103

104
        // Name of the group the currently installed artifact belongs to. For
105
        // artifact version >= 3, this is held in the header-info artifact-
106
        // provides field
107
        static const string artifact_group_key;
108

109
        // Holds the current artifact provides from the type-info header of
110
        // artifact version >= 3.
111
        // NOTE: These provides are held in a separate key due to the header-
112
        // info provides overlap with previous versions of mender artifact.
113
        static const string artifact_provides_key;
114

115
        // The key used by the standalone installer to track artifacts that have
116
        // been started, but not committed. We don't want to use the
117
        // StateDataKey for this, because it contains a lot less information.
118
        static const string standalone_state_key;
119

120
        // Name of key that state data is stored under across reboots. Uses the
121
        // StateData structure, marshalled to JSON.
122
        static const string state_data_key;
123

124
        // Added together with update modules in v2.0.0. This key is invoked if,
125
        // and only if, a client loads data using the StateDataKey, and
126
        // discovers that it is a different version than what it currently
127
        // supports. In that case it switches to using the
128
        // StateDataKeyUncommitted until the commit stage, where it switches
129
        // back to StateDataKey. This is intended to ensure that upgrading the
130
        // client to a new database schema doesn't overwrite the existing
131
        // schema, in case it is rolled back and the old client needs the
132
        // original schema again.
133
        static const string state_data_key_uncommitted;
134

135
        // Added in Mender v2.7.0. Updated every time a control map is updated
136
        // in memory.
137
        static const string update_control_maps;
138

139
        // ---------------------- NOT IN USE ANYMORE --------------------------
140
        // Key used to store the auth token.
141
        static const string auth_token_name;
142
        static const string auth_token_cache_invalidator_name;
143

144
        // END OF DATABASE KEYS -----------------------------------------------
145

146
        static const int standalone_data_version;
147

148
private:
149
#if MENDER_USE_LMDB
150
        kv_db::KeyValueDatabaseLmdb mender_store_;
151
#endif // MENDER_USE_LMDB
152
        conf::MenderConfig &config_;
153
};
154

155
// Only here to make testing easier, use MenderContext::MatchesArtifactDepends().
156
expected::ExpectedBool ArtifactMatchesContext(
157
        const ProvidesData &provides,
158
        const string &device_type,
159
        const artifact::HeaderInfo &hdr_info,
160
        const artifact::TypeInfo &type_info);
161

162
} // namespace context
163
} // namespace update
164
} // namespace mender
165

166
#endif // MENDER_COMMON_CONTEXT_HPP
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

© 2025 Coveralls, Inc