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

mendersoftware / mender / 968408678

pending completion
968408678

push

gitlab-ci

oleorhagen
feat(artifact/scripts): Add support for executing state scripts

Ticket: MEN-6636
Changelog: None

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

126 of 126 new or added lines in 4 files covered. (100.0%)

5405 of 6857 relevant lines covered (78.82%)

195.75 hits per line

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

80.65
/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,450✔
30
        return (fs::path(prefix) / suffix).string();
12,900✔
31
}
32

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

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

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

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

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

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

73
                if (matcher(file_path)) {
11✔
74
                        matching_files.push_back(file_path);
10✔
75
                }
76
        }
77

78
        return matching_files;
7✔
79
}
80

81
} // namespace path
82
} // namespace common
83
} // 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