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

mendersoftware / mender / 2460319284

17 Apr 2026 11:02AM UTC coverage: 81.435% (-0.3%) from 81.695%
2460319284

push

gitlab-ci

web-flow
Merge pull request #1938 from michalkopczan/MEN-9075-mender-marks-download-as-imcomplete-when-update-module-returns-too-fast

chore: Document stream tree flow synchronization

9181 of 11274 relevant lines covered (81.44%)

20188.59 hits per line

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

82.35
/src/common/key_value_database.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 <common/key_value_database.hpp>
16

17
#include <common/common.hpp>
18

19
namespace mender {
20
namespace common {
21
namespace key_value_database {
22

23
namespace common = mender::common;
24

25
const KeyValueDatabaseErrorCategoryClass KeyValueDatabaseErrorCategory =
26
        KeyValueDatabaseErrorCategoryClass();
27

28
const char *KeyValueDatabaseErrorCategoryClass::name() const noexcept {
×
29
        return "KeyValueDatabaseErrorCategory";
×
30
}
31

32
string KeyValueDatabaseErrorCategoryClass::message(int code) const {
3✔
33
        switch (code) {
3✔
34
        case NoError:
35
                return "Success";
×
36
        case KeyError:
37
                return "Key error";
1✔
38
        case LmdbError:
39
                return "LMDB error";
2✔
40
        case AlreadyExistsError:
41
                return "Key already exists";
×
42
        default:
43
                return "Unknown";
×
44
        }
45
}
46

47
Error MakeError(ErrorCode code, const string &msg) {
1,454✔
48
        return Error(error_condition(code, KeyValueDatabaseErrorCategory), msg);
2,348✔
49
}
50

51
expected::ExpectedBytes KeyValueDatabase::Read(const string &key) {
271✔
52
        vector<uint8_t> ret;
53
        auto err = ReadTransaction([&key, &ret](Transaction &txn) -> error::Error {
271✔
54
                auto result = txn.Read(key);
271✔
55
                if (result) {
271✔
56
                        ret = std::move(result.value());
115✔
57
                        return error::NoError;
115✔
58
                } else {
59
                        return result.error();
156✔
60
                }
61
        });
271✔
62
        if (mender::common::error::NoError != err) {
271✔
63
                return expected::unexpected(err);
312✔
64
        } else {
65
                return ret;
115✔
66
        }
67
}
68

69
error::Error KeyValueDatabase::Write(const string &key, const vector<uint8_t> &value) {
284✔
70
        return WriteTransaction(
284✔
71
                [&key, &value](Transaction &txn) -> error::Error { return txn.Write(key, value); });
852✔
72
}
73

74
error::Error KeyValueDatabase::Remove(const string &key) {
980✔
75
        return WriteTransaction([&key](Transaction &txn) -> error::Error { return txn.Remove(key); });
2,940✔
76
}
77

78
Error ReadString(Transaction &txn, const string &key, string &value_str, bool missing_ok) {
1,524✔
79
        auto ex_bytes = txn.Read(key);
1,524✔
80
        if (!ex_bytes) {
1,524✔
81
                if (!missing_ok || (ex_bytes.error().code != MakeError(KeyError, "").code)) {
3,576✔
82
                        return ex_bytes.error();
×
83
                }
84
        } else {
85
                value_str = common::StringFromByteVector(ex_bytes.value());
1,260✔
86
        }
87
        return error::NoError;
1,524✔
88
}
89

90
} // namespace key_value_database
91
} // namespace common
92
} // 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