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

mendersoftware / mender / 1073264463

15 Nov 2023 10:33AM UTC coverage: 80.186% (+0.1%) from 80.062%
1073264463

push

gitlab-ci

kacf
docs: Restore Update Control XML file for documentation purposes.

This is a partial restore of ee5dc24db79fc57, just to get the XML file
back. The feature is still removed, this is just to be able to keep it
in the documentation with a notice that says it's removed (already
merged to master in 426caf729c3191b).

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

6969 of 8691 relevant lines covered (80.19%)

9260.9 hits per line

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

63.41
/src/artifact/tar/platform/libarchive/tar.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 <artifact/tar/tar.hpp>
16

17
#include <cstdint>
18
#include <vector>
19
#include <algorithm>
20
#include <string>
21
#include <iostream>
22

23
#include <common/io.hpp>
24
#include <common/log.hpp>
25

26
namespace mender {
27
namespace tar {
28

29
using namespace std;
30

31
namespace log = mender::common::log;
32
namespace expected = mender::common::expected;
33
namespace error = mender::common::error;
34

35
using Error = error::Error;
36
using ExpectedSize = expected::ExpectedSize;
37

38
const ErrorCategoryClass ErrorCategory {};
39

40
const char *ErrorCategoryClass::name() const noexcept {
×
41
        return "TarErrorCategory";
×
42
}
43

44
string ErrorCategoryClass::message(int code) const {
×
45
        switch (code) {
×
46
        case NoError:
47
                return "Success";
×
48
        case TarReaderError:
49
                return "Error reading the tar stream";
×
50
        case TarShortReadError:
51
                return "Short read error";
×
52
        case TarEntryError:
53
                return "Error reading the tar entry";
×
54
        case TarEOFError:
55
                return "Archive EOF reached";
×
56
        }
57
        assert(false);
58
        return "Unknown";
×
59
}
60

61
Error MakeError(ErrorCode code, const string &msg) {
96✔
62
        return error::Error(error_condition(code, ErrorCategory), msg);
431✔
63
}
64

65
ExpectedSize Entry::Read(vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
3,122✔
66
        ExpectedSize read_bytes = reader_.Read(start, end);
3,122✔
67

68
        if (!read_bytes) {
3,122✔
69
                return read_bytes;
70
        }
71

72
        nr_bytes_read_ += read_bytes.value();
3,122✔
73

74
        return read_bytes;
3,122✔
75
}
76

77

78
ExpectedSize Reader::Read(vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
3,122✔
79
        return this->archive_handle_.Read(start, end);
3,122✔
80
}
81

82

83
Reader::Reader(mender::common::io::Reader &reader) :
410✔
84
        archive_handle_ {reader} {
410✔
85
}
410✔
86

87
// Read the next Tar header, and populate the meta-data:
88
// * name
89
// * Archive size
90
ExpectedEntry Reader::Next() {
1,195✔
91
        struct archive_entry *current_entry;
92

93
        if (archive_handle_.Get() == nullptr) {
1,195✔
94
                return expected::unexpected(MakeError(TarEntryError, "No underlying stream to read from"));
×
95
        }
96

97
        int r = archive_read_next_header(archive_handle_.Get(), &current_entry);
1,195✔
98
        if (r == ARCHIVE_EOF) {
1,195✔
99
                return expected::unexpected(MakeError(TarEOFError, "Reached the end of the archive"));
711✔
100
        }
101
        if (r != ARCHIVE_OK) {
958✔
102
                return expected::unexpected(MakeError(
2✔
103
                        TarReaderError,
104
                        "archive_read_next failed in LibArchive. Error code: " + to_string(r)
4✔
105
                                + " Error message: " + archive_error_string(archive_handle_.Get())));
8✔
106
        }
107

108
        const char *archive_name = archive_entry_pathname(current_entry);
956✔
109
        if (archive_name == nullptr) {
956✔
110
                return expected::unexpected(
×
111
                        MakeError(TarReaderError, "Failed to get the name of the archive entry"));
×
112
        }
113

114
        const la_int64_t archive_entry_size_ {archive_entry_size(current_entry)};
956✔
115
        if (archive_entry_size_ < 0) {
956✔
116
                return expected::unexpected(
×
117
                        MakeError(TarReaderError, "Failed to get the size of the archive"));
×
118
        }
119

120
        return Entry(archive_name, static_cast<size_t>(archive_entry_size_), *this);
1,912✔
121
}
122

123
} // namespace tar
124
} // 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

© 2025 Coveralls, Inc