v2.0.6-release (#50)
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
Reviewed-on: #50
This commit is contained in:
@@ -157,6 +157,7 @@ auto get_next_available_port(std::uint16_t first_port,
|
||||
++check_port;
|
||||
continue;
|
||||
}
|
||||
|
||||
acceptor.set_option(boost::asio::ip::tcp::acceptor::linger(true, 0));
|
||||
acceptor.bind({tcp::v4(), static_cast<std::uint16_t>(check_port)},
|
||||
error_code);
|
||||
|
52
support/src/utils/directory.cpp
Normal file
52
support/src/utils/directory.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#if defined(_WIN32)
|
||||
#include "utils/path.hpp"
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
namespace repertory::utils::directory {
|
||||
auto temp() -> std::string {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
#if defined(_WIN32)
|
||||
auto ret{utils::get_environment_variable("TEMP")};
|
||||
if (ret.empty()) {
|
||||
ret = utils::path::combine(utils::get_environment_variable("LOCALAPPDATA"),
|
||||
{"Temp"});
|
||||
}
|
||||
#else // !defined(_WIN32)
|
||||
std::string ret{"/tmp"};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (not utils::file::directory{ret}.create_directory()) {
|
||||
utils::error::handle_error(function_name,
|
||||
utils::error::create_error_message(
|
||||
{"failed to create directory", ret}));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::utils::directory
|
@@ -119,8 +119,8 @@ auto get_free_drive_space(std::string_view path)
|
||||
try {
|
||||
#if defined(_WIN32)
|
||||
ULARGE_INTEGER li{};
|
||||
if (not::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr,
|
||||
nullptr)) {
|
||||
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr,
|
||||
nullptr)) {
|
||||
throw utils::error::create_exception(
|
||||
function_name, {
|
||||
"failed to get free disk space",
|
||||
@@ -276,8 +276,8 @@ auto get_total_drive_space(std::string_view path)
|
||||
try {
|
||||
#if defined(_WIN32)
|
||||
ULARGE_INTEGER li{};
|
||||
if (not::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li,
|
||||
nullptr)) {
|
||||
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li,
|
||||
nullptr)) {
|
||||
throw utils::error::create_exception(
|
||||
function_name, {
|
||||
"failed to get total disk space",
|
||||
@@ -376,7 +376,7 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
|
||||
try {
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
auto file = file::open_file(abs_path);
|
||||
if (not*file) {
|
||||
if (not *file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ auto write_json_file(std::wstring_view path, const nlohmann::json &data)
|
||||
#endif // defined(PROJECT_ENABLE_JSON)
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBDSM)
|
||||
static constexpr const auto validate_smb_path =
|
||||
static constexpr auto validate_smb_path =
|
||||
[](std::string_view path) -> bool {
|
||||
return (not utils::string::begins_with(path, "///") &&
|
||||
utils::string::begins_with(path, "//") &&
|
||||
|
@@ -86,11 +86,13 @@ auto traverse_directory(
|
||||
struct dirent *de{nullptr};
|
||||
while (res && (de = readdir(root)) && !is_stop_requested()) {
|
||||
if (de->d_type == DT_DIR) {
|
||||
if ((std::string_view(de->d_name) != ".") &&
|
||||
(std::string_view(de->d_name) != "..")) {
|
||||
res = directory_action(repertory::utils::file::directory(
|
||||
repertory::utils::path::combine(path, {de->d_name})));
|
||||
if ((std::string_view(de->d_name) == ".") ||
|
||||
(std::string_view(de->d_name) == "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
res = directory_action(repertory::utils::file::directory(
|
||||
repertory::utils::path::combine(path, {de->d_name})));
|
||||
} else {
|
||||
res = file_action(repertory::utils::file::file(
|
||||
repertory::utils::path::combine(path, {de->d_name})));
|
||||
@@ -105,8 +107,8 @@ auto traverse_directory(
|
||||
} // namespace
|
||||
|
||||
namespace repertory::utils::file {
|
||||
auto directory::copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool {
|
||||
auto directory::copy_to(std::string_view new_path, bool overwrite) const
|
||||
-> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@@ -213,7 +215,7 @@ auto directory::exists() const -> bool {
|
||||
#if defined(_WIN32)
|
||||
return ::PathIsDirectoryA(path_.c_str()) != 0;
|
||||
#else // !defined(_WIN32)
|
||||
struct stat64 st {};
|
||||
struct stat64 st{};
|
||||
return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
@@ -266,8 +268,8 @@ auto directory::get_directories() const -> std::vector<fs_directory_t> {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto directory::create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t {
|
||||
auto directory::create_file(std::string_view file_name, bool read_only) const
|
||||
-> fs_file_t {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
|
@@ -152,19 +152,19 @@ auto find_program_in_path(const std::string &name_without_extension)
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
static constexpr const std::array<std::string_view, 4U> extension_list{
|
||||
static constexpr std::array<std::string_view, 4U> extension_list{
|
||||
".bat",
|
||||
".cmd",
|
||||
".exe",
|
||||
".ps1",
|
||||
};
|
||||
static constexpr const auto split_char = ';';
|
||||
static constexpr auto split_char = ';';
|
||||
#else // !defined(_WIN32)
|
||||
static constexpr const std::array<std::string_view, 2U> extension_list{
|
||||
static constexpr std::array<std::string_view, 2U> extension_list{
|
||||
"",
|
||||
".sh",
|
||||
};
|
||||
static constexpr const auto split_char = ':';
|
||||
static constexpr auto split_char = ':';
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto search_path_list = utils::string::split(path, split_char, false);
|
||||
@@ -274,18 +274,18 @@ auto strip_to_file_name(std::wstring path) -> std::wstring {
|
||||
}
|
||||
|
||||
auto unmake_file_uri(std::string_view uri) -> std::string {
|
||||
static constexpr const std::array<std::string_view, 23U> escape_characters = {
|
||||
static constexpr std::array<std::string_view, 23U> escape_characters = {
|
||||
{
|
||||
" ", "<", ">", "#", "%", "+", "{", "}", "|", "\\", "^", "~",
|
||||
"[", "]", "`", ";", "/", "?", ":", "@", "=", "&", "$",
|
||||
}};
|
||||
static constexpr const std::array<std::string_view, 23U>
|
||||
static constexpr std::array<std::string_view, 23U>
|
||||
escape_sequences_lower = {{
|
||||
"%20", "%3c", "%3e", "%23", "%25", "%2b", "%7b", "%7d",
|
||||
"%7c", "%5c", "%5e", "%7e", "%5b", "%5d", "%60", "%3b",
|
||||
"%2f", "%3f", "%3a", "%40", "%3d", "%26", "%24",
|
||||
}};
|
||||
static constexpr const std::array<std::string_view, 23U>
|
||||
static constexpr std::array<std::string_view, 23U>
|
||||
escape_sequences_upper = {{
|
||||
"%20", "%3C", "%3E", "%23", "%25", "%2B", "%7B", "%7D",
|
||||
"%7C", "%5C", "%5E", "%7E", "%5B", "%5D", "%60", "%3B",
|
||||
|
Reference in New Issue
Block a user