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

realm / realm-core / 2103

06 Mar 2024 03:32PM UTC coverage: 90.949% (+0.02%) from 90.931%
2103

push

Evergreen

web-flow
Merge pull request #7419 from realm/je/logging-c-api

Add ability to get logging level via C API.
Add ability to get all category names

93928 of 173072 branches covered (54.27%)

38 of 39 new or added lines in 3 files covered. (97.44%)

104 existing lines in 21 files now uncovered.

238407 of 262133 relevant lines covered (90.95%)

5612447.62 hits per line

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

81.91
/src/realm/sync/noinst/server/server_dir.cpp
1
#include <locale>
2

3
#include <realm/sync/noinst/server/server_dir.hpp>
4

5
using namespace realm;
6

7
namespace {
8

9
bool valid_virt_path_segment(const std::string& seg)
10
{
6,928✔
11
    if (seg.empty())
6,928✔
12
        return false;
20✔
13
    // Prevent `.`, `..`, and `.foo` (hidden files)
2,994✔
14
    if (seg.front() == '.')
6,908✔
15
        return false;
44✔
16
    // Prevent spurious clashes between directory names and file names
2,972✔
17
    // created by appending `.realm`, `.realm.lock`, or `.realm.management`
2,972✔
18
    // to the last component of client specified virtual paths.
2,972✔
19
    bool possible_clash = (StringData(seg).ends_with(".realm") || StringData(seg).ends_with(".realm.lock") ||
6,864✔
20
                           StringData(seg).ends_with(".realm.management"));
6,860✔
21
    if (possible_clash)
6,864✔
22
        return false;
16✔
23
    std::locale c_loc = std::locale::classic();
6,848✔
24
    for (char ch : seg) {
35,108✔
25
        if (std::isalnum(ch, c_loc)) // A-Za-z0-9
35,108✔
26
            continue;
34,112✔
27
        if (ch == '_' || ch == '-' || ch == '.' || ch == '"')
996✔
28
            continue;
970✔
29
        return false;
26✔
30
    }
26✔
31
    return true;
6,836✔
32
}
6,848✔
33

34
} // unnamed namespace
35

36

37
_impl::VirtualPathComponents _impl::parse_virtual_path(const std::string& root_path, const std::string& virt_path)
38
{
6,730✔
39
    VirtualPathComponents result;
6,730✔
40
    if (virt_path.empty())
6,730✔
41
        return result;
4✔
42

2,902✔
43
    std::string real_path = root_path;
6,726✔
44
    size_t prev_pos = 0;
6,726✔
45
    if (virt_path.front() != '/') {
6,726✔
46
        --prev_pos;
862✔
47
        real_path += '/';
862✔
48
    }
862✔
49
    for (;;) {
6,928✔
50
        ++prev_pos; // Skip previous slash
6,928✔
51
        size_t pos = virt_path.find('/', prev_pos);
6,928✔
52
        bool last = (pos == std::string::npos);
6,928✔
53
        if (last)
6,928✔
54
            pos = virt_path.size();
6,714✔
55
        std::string segment = virt_path.substr(prev_pos, pos - prev_pos);
6,928✔
56
        // Parition key style paths will be surrounded in quotes, which Windows
3,004✔
57
        // doesn't allow in paths.
3,004✔
58
        segment.erase(std::remove(segment.begin(), segment.end(), '"'), segment.end());
6,928✔
59

3,004✔
60
        if (!valid_virt_path_segment(segment))
6,928✔
61
            return result;
108✔
62

2,950✔
63
        real_path = util::File::resolve(segment, real_path);
6,820✔
64
        if (last)
6,820✔
65
            break;
6,616✔
66
        prev_pos = pos;
204✔
67
    }
204✔
68
    result.is_valid = true;
6,672✔
69
    result.real_realm_path = real_path + ".realm";
6,618✔
70
    return result;
6,618✔
71
}
6,726✔
72

73

74
bool _impl::map_virt_to_real_realm_path(const std::string& root_path, const std::string& virt_path,
75
                                        std::string& real_path)
76
{
72✔
77
    VirtualPathComponents result = parse_virtual_path(root_path, virt_path); // Throws
72✔
78
    if (result.is_valid) {
72✔
79
        real_path = std::move(result.real_realm_path);
72✔
80
        return true;
72✔
81
    }
72✔
82
    return false;
×
83
}
×
84

85

86
bool _impl::map_partial_to_reference_virt_path(const std::string& partial_path, std::string& reference_path)
87
{
×
88
    std::string root_path = "";                                                 // Immaterial
×
89
    VirtualPathComponents result = parse_virtual_path(root_path, partial_path); // Throws
×
90
    if (result.is_valid && result.is_partial_view) {
×
91
        reference_path = std::move(result.reference_path);
×
92
        return true;
×
93
    }
×
94
    return false;
×
95
}
×
96

97

98
void _impl::make_dirs(const std::string& root_path, const std::string& virt_path)
99
{
1,058✔
100
    REALM_ASSERT(!virt_path.empty());
1,058✔
101
    size_t prev_pos = 0;
1,058✔
102
    std::string real_path = root_path;
1,058✔
103
    if (virt_path.front() != '/') {
1,058✔
104
        real_path += '/';
372✔
105
        --prev_pos;
372✔
106
    }
372✔
107
    for (;;) {
1,058✔
108
        ++prev_pos; // Skip previous slash
1,058✔
109
        size_t pos = virt_path.find('/', prev_pos);
1,058✔
110
        if (pos == std::string::npos)
1,058✔
111
            break;
1,058✔
UNCOV
112
        std::string name = virt_path.substr(prev_pos, pos - prev_pos);
×
UNCOV
113
        REALM_ASSERT(valid_virt_path_segment(name));
×
UNCOV
114
        real_path = util::File::resolve(name, real_path);
×
UNCOV
115
        util::try_make_dir(real_path);
×
UNCOV
116
        prev_pos = pos;
×
UNCOV
117
    }
×
118
}
1,058✔
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