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

mendersoftware / mender-flash / 1056872479

30 Oct 2023 08:37AM UTC coverage: 67.32% (-0.3%) from 67.647%
1056872479

push

gitlab-ci

web-flow
Merge pull request #6 from lluiscampos/MEN-6802-fix-read-from-pipe

MEN-6802: Fix read from pipe

4 of 4 new or added lines in 1 file covered. (100.0%)

206 of 306 relevant lines covered (67.32%)

15.91 hits per line

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

68.92
/libflash/fileio.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 <fileio.hpp>
16
#include <sstream>
17

18
mender::io::FileReader::FileReader(mender::io::File f) :
5✔
19
        fd_(f) {
5✔
20
}
5✔
21

22
mender::io::FileReader::~FileReader() {
5✔
23
        if (fd_ != mender::io::GetInvalidFile()) {
5✔
24
                mender::io::Close(fd_);
2✔
25
        }
26
}
5✔
27

28
ExpectedSize mender::io::FileReader::Read(
66✔
29
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
30
        return mender::io::Read(fd_, &*start, end - start);
66✔
31
}
32

33
ExpectedSize mender::io::FileReader::Tell() const {
×
34
        return mender::io::Tell(fd_);
×
35
}
36

37
mender::io::InputStreamReader::InputStreamReader() :
×
38
        FileReader(GetInputStream()) {
×
39
}
×
40

41
ExpectedSize mender::io::InputStreamReader::Read(
×
42
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
43
        auto res = FileReader::Read(start, end);
×
44
        if (!res) {
×
45
                return res;
×
46
        }
47
        readBytes_ += res.value();
×
48
        return res;
×
49
}
50

51
ExpectedSize mender::io::InputStreamReader::Tell() const {
×
52
        return readBytes_;
×
53
}
54

55
mender::io::LimitedFlushingWriter::LimitedFlushingWriter(
2✔
56
        mender::io::File f, size_t limit, uint32_t flushInterval) :
2✔
57
        FileWriter(f),
58
        writingLimit_(limit),
59
        flushIntervalBytes_(flushInterval) {
2✔
60
}
2✔
61

62
ExpectedSize mender::io::LimitedFlushingWriter::Write(
2✔
63
        vector<uint8_t>::const_iterator start, vector<uint8_t>::const_iterator end) {
64
        auto pos = mender::io::Tell(fd_);
4✔
65
        if (!pos.has_value()) {
2✔
66
                return pos;
×
67
        }
68
        auto dataLen = end - start;
2✔
69
        if (writingLimit_ && pos.value() + dataLen > writingLimit_) {
2✔
70
                std::stringstream ss;
1✔
71
                ss << "Error writing beyound the limit of " << writingLimit_ << " bytes";
1✔
72
                return expected::unexpected(Error(std::error_condition(std::errc::io_error), ss.str()));
2✔
73
        }
74
        auto res = FileWriter::Write(start, end);
2✔
75
        if (res) {
1✔
76
                unflushedBytesWritten_ += res.value();
1✔
77
                if (unflushedBytesWritten_ >= flushIntervalBytes_) {
1✔
78
                        auto flushRes = mender::io::Flush(fd_);
1✔
79
                        if (NoError != flushRes) {
1✔
80
                                return expected::unexpected(
×
81
                                        Error(std::error_condition(std::errc::io_error), flushRes.message));
×
82
                        } else {
83
                                unflushedBytesWritten_ -= flushIntervalBytes_;
1✔
84
                        }
85
                }
86
        }
87
        return res;
1✔
88
}
89

90
mender::io::FileWriter::FileWriter(File f) :
10✔
91
        fd_(f) {
10✔
92
}
10✔
93

94
mender::io::FileWriter::~FileWriter() {
10✔
95
        if (fd_ != mender::io::GetInvalidFile()) {
10✔
96
                mender::io::Close(fd_);
10✔
97
        }
98
}
10✔
99

100
ExpectedSize mender::io::FileWriter::Write(
55✔
101
        vector<uint8_t>::const_iterator start, vector<uint8_t>::const_iterator end) {
102
        return mender::io::Write(fd_, &*start, end - start);
55✔
103
}
104

105
mender::io::FileReadWriter::FileReadWriter(File f) :
8✔
106
        fd_(f) {
8✔
107
}
8✔
108

109
mender::io::FileReadWriter::~FileReadWriter() {
8✔
110
        if (fd_ != mender::io::GetInvalidFile()) {
8✔
111
                mender::io::Close(fd_);
8✔
112
        }
113
}
8✔
114

115
ExpectedSize mender::io::FileReadWriter::Read(
34✔
116
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
117
        return mender::io::Read(fd_, &*start, end - start);
34✔
118
}
119

120
ExpectedSize mender::io::FileReadWriter::Write(
×
121
        vector<uint8_t>::const_iterator start, vector<uint8_t>::const_iterator end) {
122
        return mender::io::Write(fd_, &*start, end - start);
×
123
}
124

125
mender::io::FileReadWriterSeeker::FileReadWriterSeeker(FileWriter &writer) :
×
126
        FileReadWriter(writer.fd_),
127
        writer_(writer) {
×
128
}
×
129

130
ExpectedSize mender::io::FileReadWriterSeeker::Write(
54✔
131
        vector<uint8_t>::const_iterator start, vector<uint8_t>::const_iterator end) {
132
        return writer_.Write(start, end);
54✔
133
}
134

135
Error mender::io::FileReadWriterSeeker::SeekSet(uint64_t pos) {
118✔
136
        return mender::io::SeekSet(fd_, pos);
118✔
137
}
138

139
ExpectedSize mender::io::FileReadWriterSeeker::Tell() const {
×
140
        return mender::io::Tell(fd_);
×
141
}
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