0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-19 19:33:45 +02:00

ircd:🆑:code: Add construction from files and directories.

This commit is contained in:
Jason Volk 2022-10-23 19:43:38 +00:00
parent 5aeadc2d52
commit 601a7a3a6a
2 changed files with 51 additions and 0 deletions

View file

@ -37,10 +37,13 @@ struct ircd::cl::code
void create(const vector_view<const string_view> &srcs);
public:
IRCD_OVERLOAD(path);
explicit code(const const_buffer &bc);
explicit code(const vector_view<const const_buffer> &bins);
code(const vector_view<const string_view> &srcs);
code(const string_view &src);
code(path_t, const vector_view<const string_view> &paths);
code(path_t, const string_view &path);
code() = default;
code(code &&) noexcept;
code(const code &) = delete;

View file

@ -1463,6 +1463,54 @@ ircd::cl::code::iov_max
// code::code
//
ircd::cl::code::code(path_t,
const string_view &paths)
:code
{
path,
vector_view<const string_view>(&paths, 1),
}
{
}
ircd::cl::code::code(path_t,
const vector_view<const string_view> &paths_)
{
static const auto is_cl
{
[](const auto &path)
{
return fs::is_reg(path) && fs::is_extension(path, ".cl");
}
};
std::vector<std::string> buf;
for(const auto &path : paths_)
if(fs::is_dir(path))
{
for(const auto &file : fs::ls(path))
if(is_cl(file))
buf.emplace_back(fs::read(fs::fd(file)));
}
else if(is_cl(path))
buf.emplace_back(fs::read(fs::fd(path)));
const auto count(buf.size());
if(unlikely(count > iov_max))
throw error
{
"Maximum number of sources exceeded: lim:%zu got:%zu",
iov_max,
count,
};
string_view src[count];
for(uint i(0); i < count; ++i)
src[i] = buf[i];
create(vector_view<const string_view>(src, count));
}
ircd::cl::code::code(const string_view &src)
:code
{