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

mendersoftware / mender / 974575668

21 Aug 2023 12:04PM UTC coverage: 78.829% (-0.05%) from 78.877%
974575668

push

gitlab-ci

kacf
chore: Implement pushing of logs to the server.

Ticket: MEN-6581

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

18 of 18 new or added lines in 2 files covered. (100.0%)

5492 of 6967 relevant lines covered (78.83%)

238.75 hits per line

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

81.82
/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 <string>
18

19
#include <filesystem>
20
#include <unordered_set>
21

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

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

29
string JoinOne(const string &prefix, const string &suffix) {
6,656✔
30
        return (fs::path(prefix) / suffix).string();
13,312✔
31
}
32

33
string BaseName(const string &path) {
56✔
34
        return fs::path(path).filename().string();
112✔
35
}
36

37
string DirName(const string &path) {
46✔
38
        return fs::path(path).parent_path().string();
92✔
39
}
40

41
bool IsAbsolute(const string &path) {
778✔
42
        return fs::path(path).is_absolute();
778✔
43
}
44

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

49
expected::ExpectedBool IsExecutable(const string &file_path) {
11✔
50
        fs::perms perms = fs::status(file_path).permissions();
11✔
51
        if ((perms & (fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec))
11✔
52
                == fs::perms::none) {
11✔
53
                log::Warning("'" + file_path + "' is not executable");
1✔
54
                return false;
1✔
55
        }
56
        return true;
10✔
57
}
58

59
expected::ExpectedUnorderedSet<string> ListFiles(
7✔
60
        const string &in_directory, function<bool(string)> matcher) {
61
        unordered_set<string> matching_files {};
14✔
62
        fs::path dir_path(in_directory);
14✔
63
        if (!fs::exists(dir_path)) {
7✔
64
                auto err {errno};
×
65
                return expected::unexpected(error::Error(
×
66
                        generic_category().default_error_condition(err),
×
67
                        "No such file or directory: " + in_directory));
×
68
        }
69

70
        for (const auto &entry : fs::directory_iterator {dir_path}) {
32✔
71
                fs::path file_path = entry.path();
11✔
72
                if (!fs::is_regular_file(file_path)) {
11✔
73
                        log::Warning("'" + file_path.string() + "'" + " is not a regular file. Ignoring.");
×
74
                        continue;
×
75
                }
76

77
                if (matcher(file_path)) {
11✔
78
                        matching_files.insert(file_path);
10✔
79
                }
80
        }
81

82
        return matching_files;
7✔
83
}
84

85
} // namespace path
86
} // namespace common
87
} // 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