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

mendersoftware / mender / 1022753986

02 Oct 2023 10:37AM UTC coverage: 78.168% (-2.0%) from 80.127%
1022753986

push

gitlab-ci

oleorhagen
feat: Run the authentication loop once upon bootstrap

Ticket: MEN-6658
Changelog: None

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>

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

6996 of 8950 relevant lines covered (78.17%)

10353.4 hits per line

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

87.8
/common/path/platform/c++17/path.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/path.hpp>
16

17
#include <filesystem>
18
#include <string>
19
#include <unordered_set>
20

21
#include <common/error.hpp>
22

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

27
using namespace std;
28
namespace fs = std::filesystem;
29

30
string JoinOne(const string &prefix, const string &suffix) {
12,695✔
31
        return (fs::path(prefix) / suffix).string();
25,390✔
32
}
33

34
string BaseName(const string &path) {
27,344✔
35
        return fs::path(path).filename().string();
54,688✔
36
}
37

38
string DirName(const string &path) {
89✔
39
        return fs::path(path).parent_path().string();
178✔
40
}
41

42
bool IsAbsolute(const string &path) {
1,946✔
43
        return fs::path(path).is_absolute();
1,946✔
44
}
45

46
bool FileExists(const string &path) {
700✔
47
        return fs::exists(path);
700✔
48
}
49

50
error::Error FileDelete(const string &path) {
1✔
51
        error_code ec;
1✔
52
        bool deleted = fs::remove(fs::path(path), ec);
1✔
53
        if (not deleted) {
1✔
54
                return error::Error(
55
                        ec.default_error_condition(),
×
56
                        "Failed to remove the file: '" + path + "'. error: " + ec.message());
×
57
        }
58
        return error::NoError;
1✔
59
}
60

61
expected::ExpectedBool IsExecutable(const string &file_path, const bool warn) {
684✔
62
        fs::perms perms = fs::status(file_path).permissions();
684✔
63
        if ((perms & (fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec))
684✔
64
                == fs::perms::none) {
684✔
65
                if (warn) {
×
66
                        log::Warning("'" + file_path + "' is not executable");
×
67
                }
68
                return false;
×
69
        }
70
        return true;
684✔
71
}
72

73
expected::ExpectedUnorderedSet<string> ListFiles(
1,274✔
74
        const string &in_directory, function<bool(string)> matcher) {
75
        unordered_set<string> matching_files {};
2,548✔
76
        fs::path dir_path(in_directory);
2,548✔
77
        if (!fs::exists(dir_path)) {
1,274✔
78
                auto err {errno};
52✔
79
                return expected::unexpected(error::Error(
52✔
80
                        generic_category().default_error_condition(err),
52✔
81
                        "No such file or directory: " + in_directory));
156✔
82
        }
83

84
        for (const auto &entry : fs::directory_iterator {dir_path}) {
31,213✔
85
                fs::path file_path = entry.path();
27,547✔
86
                if (!fs::is_regular_file(file_path)) {
27,547✔
87
                        log::Warning("'" + file_path.string() + "'" + " is not a regular file. Ignoring.");
291✔
88
                        continue;
291✔
89
                }
90

91
                if (matcher(file_path)) {
27,256✔
92
                        matching_files.insert(file_path);
684✔
93
                }
94
        }
95

96
        return matching_files;
1,222✔
97
}
98

99
} // namespace path
100
} // namespace common
101
} // 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