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

paticcaa / pain / 17468034979

04 Sep 2025 02:57PM UTC coverage: 54.07%. First build
17468034979

Pull #10

github

web-flow
Merge 917eee996 into e6f85a326
Pull Request #10: check index

1452 of 3700 branches covered (39.24%)

Branch coverage included in aggregate %.

15 of 17 new or added lines in 2 files covered. (88.24%)

1703 of 2135 relevant lines covered (79.77%)

437.1 hits per line

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

54.47
/src/deva/deva.cc
1
#include "deva/deva.h"
2
#include <pain/base/plog.h>
3
#include <pain/base/uuid.h>
4
#include "deva/macro.h"
5

6
#define DEVA_METHOD(name)                                                                                              \
7
    Status Deva::name([[maybe_unused]] int32_t version,                                                                \
8
                      [[maybe_unused]] const pain::proto::deva::store::name##Request* request,                         \
9
                      [[maybe_unused]] pain::proto::deva::store::name##Response* response,                             \
10
                      [[maybe_unused]] int64_t index)
11

12
namespace pain::deva {
13

14
Status Deva::create(const std::string& path, const UUID& id, FileType type) {
75✔
15
    SPAN(span);
375!
16
    PLOG_DEBUG(("desc", "create")("path", path)("id", id.str())("type", type));
74✔
17
    // get parent
18
    std::filesystem::path file_path(path);
75!
19
    auto dir = file_path.parent_path();
75!
20
    auto filename = file_path.filename();
75!
21
    auto file_type = FileType::kFile;
75✔
22
    UUID parent_dir_uuid;
75✔
23
    auto status = _namespace.lookup(dir.c_str(), &parent_dir_uuid, &file_type);
75!
24
    if (!status.ok()) {
75!
25
        return status;
×
26
    }
27

28
    if (file_type != FileType::kDirectory) {
74!
29
        return Status(EINVAL, fmt::format("{} is not a directory", dir.c_str()));
×
30
    }
31

32
    UUID file_uuid(id.high(), id.low());
74✔
33
    status = _namespace.create(parent_dir_uuid, filename, type, file_uuid);
75!
34
    if (!status.ok()) {
73!
35
        return status;
×
36
    }
37

38
    return Status::OK();
73✔
39
}
223✔
40

41
DEVA_METHOD(CreateFile) {
36✔
42
    SPAN(span);
180!
43
    PLOG_DEBUG(("desc", "create_file")("version", version)("index", index)("request", request->DebugString()));
36✔
44
    auto& path = request->path();
36!
45
    auto& file_id = request->file_id();
36!
46
    UUID file_uuid(file_id.high(), file_id.low());
36!
47
    auto status = create(path, file_uuid, FileType::kFile);
35!
48
    if (!status.ok()) {
36!
49
        return status;
×
50
    }
51
    auto file_info = response->mutable_file_info();
36!
52
    file_info->mutable_file_id()->set_high(file_uuid.high());
36!
53
    file_info->mutable_file_id()->set_low(file_uuid.low());
36!
54
    file_info->set_type(pain::proto::FileType::FILE_TYPE_FILE);
36!
55
    file_info->set_size(0);
36!
56
    file_info->set_atime(request->atime());
36!
57
    file_info->set_mtime(request->mtime());
36!
58
    file_info->set_ctime(request->ctime());
36!
59
    file_info->set_mode(request->mode());
36!
60
    file_info->set_uid(request->uid());
36!
61
    file_info->set_gid(request->gid());
36!
62
    _file_infos[file_uuid] = *file_info;
36!
63
    return Status::OK();
36✔
64
}
108✔
65

66
DEVA_METHOD(CreateDir) {
38✔
67
    SPAN(span);
194!
68
    PLOG_DEBUG(("desc", "create_dir")("version", version)("index", index)("request", request->DebugString()));
39✔
69
    auto& path = request->path();
39!
70
    auto& dir_id = request->dir_id();
39!
71
    UUID dir_uuid(dir_id.high(), dir_id.low());
39!
72
    auto status = create(path, dir_uuid, FileType::kDirectory);
39!
73
    if (!status.ok()) {
39!
74
        return status;
×
75
    }
76
    auto file_info = response->mutable_file_info();
39!
77
    file_info->mutable_file_id()->set_high(dir_uuid.high());
39!
78
    file_info->mutable_file_id()->set_low(dir_uuid.low());
39!
79
    file_info->set_type(pain::proto::FileType::FILE_TYPE_DIRECTORY);
39!
80
    file_info->set_size(0);
39!
81
    file_info->set_atime(request->atime());
39!
82
    file_info->set_mtime(request->mtime());
39!
83
    file_info->set_ctime(request->ctime());
39!
84
    file_info->set_mode(request->mode());
39!
85
    file_info->set_uid(request->uid());
39!
86
    file_info->set_gid(request->gid());
39!
87
    _file_infos[dir_uuid] = *file_info;
39!
88
    return Status::OK();
39✔
89
}
117✔
90

91
DEVA_METHOD(ReadDir) {
2✔
92
    SPAN(span);
10!
93
    PLOG_DEBUG(("desc", "read_dir")("version", version)("index", index)("request", request->DebugString()));
2✔
94
    auto& path = request->path();
2!
95
    UUID parent_dir_uuid;
2✔
96
    FileType file_type = FileType::kNone;
2✔
97
    auto status = _namespace.lookup(path.c_str(), &parent_dir_uuid, &file_type);
2!
98
    if (!status.ok()) {
2!
99
        return status;
×
100
    }
101
    if (file_type != FileType::kDirectory) {
2!
102
        return Status(EINVAL, fmt::format("{} is not a directory", path.c_str()));
×
103
    }
104
    std::list<DirEntry> entries;
2✔
105
    _namespace.list(parent_dir_uuid, &entries);
2!
106
    for (auto& entry : entries) {
23✔
107
        auto dir_entry = response->add_entries();
21!
108
        dir_entry->mutable_file_id()->set_high(entry.inode.high());
21!
109
        dir_entry->mutable_file_id()->set_low(entry.inode.low());
21!
110
        dir_entry->set_type(static_cast<pain::proto::FileType>(entry.type));
21!
111
        dir_entry->set_name(std::move(entry.name));
21✔
112
    }
113
    return Status::OK();
2✔
114
}
6✔
115

116
DEVA_METHOD(RemoveFile) {
×
117
    SPAN(span);
×
118
    PLOG_INFO(("desc", "remove_file")("version", version)("index", index));
×
119
    return Status::OK();
×
120
}
×
121

122
DEVA_METHOD(SealFile) {
×
123
    SPAN(span);
×
124
    PLOG_INFO(("desc", "seal_file")("version", version)("index", index));
×
125
    return Status::OK();
×
126
}
×
127

128
DEVA_METHOD(CreateChunk) {
×
129
    SPAN(span);
×
130
    PLOG_INFO(("desc", "remove")("version", version)("index", index));
×
131
    return Status::OK();
×
132
}
×
133

134
DEVA_METHOD(CheckInChunk) {
×
135
    SPAN(span);
×
136
    PLOG_INFO(("desc", "seal")("version", version)("index", index));
×
137
    return Status::OK();
×
138
}
×
139

140
DEVA_METHOD(SealChunk) {
×
141
    SPAN(span);
×
142
    PLOG_INFO(("desc", "create_chunk")("version", version)("index", index));
×
143
    return Status::OK();
×
144
}
×
145

146
DEVA_METHOD(SealAndNewChunk) {
×
147
    SPAN(span);
×
148
    PLOG_INFO(("desc", "remove_chunk")("version", version)("index", index));
×
149
    return Status::OK();
×
150
}
×
151

152
Status Deva::set_applied_index(int64_t index) {
77✔
153
    if (index <= _applied_index) {
77✔
154
        PLOG_WARN(("desc", "index is applied already")("index", index));
2✔
155
        return Status::OK();
2✔
156
    }
157
    _applied_index = index;
75✔
158
    return _store->hset(_meta_key, _applied_index_key, std::to_string(index));
75!
159
}
160

161
Status Deva::save_snapshot(std::string_view path, std::vector<std::string>* files) {
4✔
162
    return _store->check_point(path.data(), files);
4✔
163
}
164

165
Status Deva::load_snapshot(std::string_view path) {
3✔
166
    auto status = _store->recover(path.data());
3!
167
    if (!status.ok()) {
3!
NEW
168
        return status;
×
169
    }
170
    // get applied index
171
    std::string applied_index_str;
3✔
172
    status = _store->hget(_meta_key, _applied_index_key, &applied_index_str);
3!
173
    if (!status.ok()) {
3!
NEW
174
        return status;
×
175
    }
176
    _applied_index = std::stoll(applied_index_str);
3!
177
    return Status::OK();
3✔
178
}
3✔
179

180
} // namespace pain::deva
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