mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::fs: Normalize buffering for path interface; add path features.
This commit is contained in:
parent
2886924bf0
commit
5b3bee79a6
5 changed files with 99 additions and 26 deletions
|
@ -31,15 +31,22 @@ namespace ircd::fs
|
|||
filesystem::path _path(const vector_view<const std::string> &);
|
||||
|
||||
string_view path(const base &) noexcept;
|
||||
std::string path(const base &, const string_view &);
|
||||
std::string path(const vector_view<const string_view> &);
|
||||
std::string path(const vector_view<const std::string> &);
|
||||
std::string path(const filesystem::path &);
|
||||
string_view path(const mutable_buffer &, const base &, const string_view &);
|
||||
string_view path(const mutable_buffer &, const vector_view<const string_view> &);
|
||||
string_view path(const mutable_buffer &, const vector_view<const std::string> &);
|
||||
string_view path(const mutable_buffer &, const filesystem::path &);
|
||||
|
||||
size_t name_max_len(const string_view &path);
|
||||
size_t path_max_len(const string_view &path);
|
||||
bool is_relative(const string_view &path);
|
||||
bool is_absolute(const string_view &path);
|
||||
|
||||
string_view extension(const mutable_buffer &, const string_view &path, const string_view &replace);
|
||||
string_view extension(const mutable_buffer &, const string_view &path);
|
||||
string_view filename(const mutable_buffer &, const string_view &path);
|
||||
string_view parent(const mutable_buffer &, const string_view &path);
|
||||
|
||||
long pathconf(const string_view &path, const int &arg);
|
||||
size_t name_max_len(const string_view &path);
|
||||
size_t path_max_len(const string_view &path);
|
||||
|
||||
string_view cwd(const mutable_buffer &buf);
|
||||
std::string cwd();
|
||||
|
|
18
ircd/db.cc
18
ircd/db.cc
|
@ -246,7 +246,11 @@ ircd::db::direct_io_test_file_path()
|
|||
"SUPPORTS_DIRECT_IO"_sv
|
||||
};
|
||||
|
||||
return fs::path(fs::DB, test_file_name);
|
||||
return ircd::string(fs::PATH_MAX_LEN, []
|
||||
(const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, fs::DB, test_file_name);
|
||||
});
|
||||
}
|
||||
|
||||
decltype(ircd::db::compressions)
|
||||
|
@ -3268,7 +3272,11 @@ ircd::db::database::sst::dump::dump(db::column column,
|
|||
fs::path(fs::DB), db::name(d), db::name(c)
|
||||
};
|
||||
|
||||
path = fs::path(path_parts);
|
||||
path = ircd::string(fs::PATH_MAX_LEN, [&path_parts]
|
||||
(const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, path_parts);
|
||||
});
|
||||
}
|
||||
|
||||
rocksdb::Options opts(d.d->GetOptions(c));
|
||||
|
@ -7317,7 +7325,11 @@ ircd::db::path(const string_view &name,
|
|||
prefix, name, lex_cast(checkpoint)
|
||||
};
|
||||
|
||||
return fs::path(parts);
|
||||
return ircd::string(fs::PATH_MAX_LEN, [&parts]
|
||||
(const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, parts);
|
||||
});
|
||||
}
|
||||
|
||||
std::pair<ircd::string_view, uint64_t>
|
||||
|
|
62
ircd/fs.cc
62
ircd/fs.cc
|
@ -1407,30 +1407,68 @@ ircd::fs::pathconf(const string_view &path,
|
|||
return syscall(::pathconf, path_str(path), arg);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::fs::filename(const mutable_buffer &buf,
|
||||
const string_view &p)
|
||||
{
|
||||
return path(buf, _path(p).filename());
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::fs::extension(const mutable_buffer &buf,
|
||||
const string_view &p)
|
||||
{
|
||||
return path(buf, _path(p).extension());
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::fs::extension(const mutable_buffer &buf,
|
||||
const string_view &p,
|
||||
const string_view &replace)
|
||||
{
|
||||
return path(buf, _path(p).replace_extension(_path(replace)));
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::is_relative(const string_view &p)
|
||||
{
|
||||
return _path(p).is_relative();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::is_absolute(const string_view &p)
|
||||
{
|
||||
return _path(p).is_absolute();
|
||||
}
|
||||
|
||||
//
|
||||
// fs::path()
|
||||
//
|
||||
|
||||
std::string
|
||||
ircd::fs::path(const filesystem::path &path)
|
||||
ircd::string_view
|
||||
ircd::fs::path(const mutable_buffer &buf,
|
||||
const filesystem::path &path)
|
||||
{
|
||||
return path.string();
|
||||
return strlcpy(buf, path.c_str());
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::fs::path(const vector_view<const std::string> &list)
|
||||
ircd::string_view
|
||||
ircd::fs::path(const mutable_buffer &buf,
|
||||
const vector_view<const std::string> &list)
|
||||
{
|
||||
return _path(list).string();
|
||||
return strlcpy(buf, _path(list).c_str());
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::fs::path(const vector_view<const string_view> &list)
|
||||
ircd::string_view
|
||||
ircd::fs::path(const mutable_buffer &buf,
|
||||
const vector_view<const string_view> &list)
|
||||
{
|
||||
return _path(list).string();
|
||||
return strlcpy(buf, _path(list).c_str());
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::fs::path(const base &base,
|
||||
ircd::string_view
|
||||
ircd::fs::path(const mutable_buffer &buf,
|
||||
const base &base,
|
||||
const string_view &rest)
|
||||
{
|
||||
const auto p
|
||||
|
@ -1442,7 +1480,7 @@ ircd::fs::path(const base &base,
|
|||
})
|
||||
};
|
||||
|
||||
return p.string();
|
||||
return strlcpy(buf, p.c_str());
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
|
|
|
@ -140,7 +140,11 @@ catch(const std::exception &e)
|
|||
std::string
|
||||
ircd::log::file_path(const level &lev)
|
||||
{
|
||||
return fs::path(fs::LOG, reflect(lev));
|
||||
return string(fs::PATH_MAX_LEN, [&lev]
|
||||
(const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, fs::LOG, reflect(lev));
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -77,17 +77,26 @@ init_my_tls_crt()
|
|||
|
||||
const std::string private_key_file
|
||||
{
|
||||
fs::path(private_key_path_parts)
|
||||
ircd::string(fs::PATH_MAX_LEN, [&](const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, private_key_path_parts);
|
||||
})
|
||||
};
|
||||
|
||||
const std::string public_key_file
|
||||
{
|
||||
fs::path(public_key_path_parts)
|
||||
ircd::string(fs::PATH_MAX_LEN, [&](const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, public_key_path_parts);
|
||||
})
|
||||
};
|
||||
|
||||
const std::string cert_file
|
||||
{
|
||||
fs::path(certificate_path_parts)
|
||||
ircd::string(fs::PATH_MAX_LEN, [&](const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, certificate_path_parts);
|
||||
})
|
||||
};
|
||||
|
||||
if(!fs::exists(private_key_file))
|
||||
|
@ -242,7 +251,10 @@ init_my_ed25519()
|
|||
|
||||
const std::string sk_file
|
||||
{
|
||||
fs::path(path_parts)
|
||||
ircd::string(fs::PATH_MAX_LEN, [&](const mutable_buffer &buf)
|
||||
{
|
||||
return fs::path(buf, path_parts);
|
||||
})
|
||||
};
|
||||
|
||||
if(fs::exists(sk_file))
|
||||
|
|
Loading…
Reference in a new issue