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

mendersoftware / mender / 1279619216

06 May 2024 07:27AM UTC coverage: 75.594% (+0.03%) from 75.566%
1279619216

push

gitlab-ci

web-flow
Merge pull request #1618 from danielskinstad/arefilesidentical

chore: function for checking if files are identical

17 of 19 new or added lines in 1 file covered. (89.47%)

7062 of 9342 relevant lines covered (75.59%)

11668.23 hits per line

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

89.47
/src/common/path/path.cpp
1
// Copyright 2024 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/io.hpp>
16
#include <common/path.hpp>
17

18
#include <functional>
19
#include <iterator>
20
#include <string>
21

22
namespace mender {
23
namespace common {
24
namespace path {
25

26
using namespace std;
27
namespace io = mender::common::io;
28

29
expected::ExpectedBool AreFilesIdentical(const string &file_one, const string &file_two) {
3✔
30
        auto file_one_expected_stream = io::OpenIfstream(file_one);
3✔
31
        if (!file_one_expected_stream) {
3✔
NEW
32
                return expected::unexpected(file_one_expected_stream.error());
×
33
        }
34
        auto file_two_expected_stream = io::OpenIfstream(file_two);
3✔
35
        if (!file_two_expected_stream) {
3✔
NEW
36
                return expected::unexpected(file_two_expected_stream.error());
×
37
        }
38

39
        auto &file_one_stream = file_one_expected_stream.value();
3✔
40
        auto &file_two_stream = file_two_expected_stream.value();
3✔
41

42
        // Compare file sizes
43
        file_one_stream.seekg(0, ios::end);
3✔
44
        file_two_stream.seekg(0, ios::end);
3✔
45
        if (file_one_stream.tellg() != file_two_stream.tellg()) {
3✔
46
                return false;
47
        }
48
        file_one_stream.seekg(0, ios::beg);
3✔
49
        file_two_stream.seekg(0, ios::beg);
3✔
50

51
        string file_one_contents {
52
                istreambuf_iterator<char>(file_one_stream), istreambuf_iterator<char>()};
3✔
53
        string file_two_contents {
54
                istreambuf_iterator<char>(file_two_stream), istreambuf_iterator<char>()};
3✔
55

56
        size_t file_one_hash = std::hash<string> {}(file_one_contents);
3✔
57
        size_t file_two_hash = std::hash<string> {}(file_two_contents);
3✔
58

59

60
        return file_one_hash == file_two_hash;
3✔
61
}
62

63
} // namespace path
64
} // namespace common
65
} // 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