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

paticcaa / pain / 17370558666

01 Sep 2025 07:19AM UTC coverage: 55.963% (+0.05%) from 55.914%
17370558666

push

github

ivanallen
add readdir

Signed-off-by: allen <1007729991@qq.com>

1385 of 3306 branches covered (41.89%)

Branch coverage included in aggregate %.

50 of 57 new or added lines in 8 files covered. (87.72%)

1623 of 2069 relevant lines covered (78.44%)

436.13 hits per line

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

51.78
/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]] const pain::proto::deva::store::name##Request* request,                         \
8
                      [[maybe_unused]] pain::proto::deva::store::name##Response* response,                             \
9
                      [[maybe_unused]] int64_t index)
10

11
namespace pain::deva {
12

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

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

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

37
    return Status::OK();
67✔
38
}
200✔
39

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

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

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

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

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

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

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

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

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

151
Status Deva::save_snapshot(std::string_view path, std::vector<std::string>* files) {
×
152
    std::ignore = path;
×
153
    std::ignore = files;
×
154
    return Status::OK();
×
155
}
156

157
Status Deva::load_snapshot(std::string_view path) {
×
158
    std::ignore = path;
×
159
    return Status::OK();
×
160
}
161

162
} // 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