updated build system
All checks were successful
Public/monitarr/pipeline/head This commit looks good
All checks were successful
Public/monitarr/pipeline/head This commit looks good
This commit is contained in:
@@ -14,7 +14,6 @@ set(GCC_VERSION 14.2.0)
|
|||||||
set(GTEST_VERSION 1.16.0)
|
set(GTEST_VERSION 1.16.0)
|
||||||
set(ICU_VERSION 76-1)
|
set(ICU_VERSION 76-1)
|
||||||
set(JSON_VERSION 3.12.0)
|
set(JSON_VERSION 3.12.0)
|
||||||
set(MESA_VERSION 23.3.3)
|
|
||||||
set(MINGW_VERSION 12.0.0)
|
set(MINGW_VERSION 12.0.0)
|
||||||
set(OPENSSL_VERSION 3.5.0)
|
set(OPENSSL_VERSION 3.5.0)
|
||||||
set(PKG_CONFIG_VERSION 0.29.2)
|
set(PKG_CONFIG_VERSION 0.29.2)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ PROJECT_VERSIONS[GCC]="14.2.0"
|
|||||||
PROJECT_VERSIONS[GTEST]="1.16.0"
|
PROJECT_VERSIONS[GTEST]="1.16.0"
|
||||||
PROJECT_VERSIONS[ICU]="76-1"
|
PROJECT_VERSIONS[ICU]="76-1"
|
||||||
PROJECT_VERSIONS[JSON]="3.12.0"
|
PROJECT_VERSIONS[JSON]="3.12.0"
|
||||||
PROJECT_VERSIONS[MESA]="23.3.3"
|
|
||||||
PROJECT_VERSIONS[MINGW]="12.0.0"
|
PROJECT_VERSIONS[MINGW]="12.0.0"
|
||||||
PROJECT_VERSIONS[OPENSSL]="3.5.0"
|
PROJECT_VERSIONS[OPENSSL]="3.5.0"
|
||||||
PROJECT_VERSIONS[PKG_CONFIG]="0.29.2"
|
PROJECT_VERSIONS[PKG_CONFIG]="0.29.2"
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
#include "utils/types/file/i_file.hpp"
|
#include "utils/types/file/i_file.hpp"
|
||||||
#include "utils/types/file/i_fs_item.hpp"
|
#include "utils/types/file/i_fs_item.hpp"
|
||||||
|
|
||||||
|
namespace repertory::utils::directory {
|
||||||
|
[[nodiscard]] auto temp() -> std::string;
|
||||||
|
}
|
||||||
|
|
||||||
namespace monitarr::utils::file {
|
namespace monitarr::utils::file {
|
||||||
[[nodiscard]] auto change_to_process_directory() -> bool;
|
[[nodiscard]] auto change_to_process_directory() -> bool;
|
||||||
|
|
||||||
|
|||||||
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 monitarr::utils::directory {
|
||||||
|
auto temp() -> std::string {
|
||||||
|
MONITARR_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 monitarr::utils::directory
|
||||||
@@ -86,11 +86,13 @@ auto traverse_directory(
|
|||||||
struct dirent *de{nullptr};
|
struct dirent *de{nullptr};
|
||||||
while (res && (de = readdir(root)) && !is_stop_requested()) {
|
while (res && (de = readdir(root)) && !is_stop_requested()) {
|
||||||
if (de->d_type == DT_DIR) {
|
if (de->d_type == DT_DIR) {
|
||||||
if ((std::string_view(de->d_name) != ".") &&
|
if ((std::string_view(de->d_name) == ".") ||
|
||||||
(std::string_view(de->d_name) != "..")) {
|
(std::string_view(de->d_name) == "..")) {
|
||||||
res = directory_action(monitarr::utils::file::directory(
|
continue;
|
||||||
monitarr::utils::path::combine(path, {de->d_name})));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = directory_action(monitarr::utils::file::directory(
|
||||||
|
monitarr::utils::path::combine(path, {de->d_name})));
|
||||||
} else {
|
} else {
|
||||||
res = file_action(monitarr::utils::file::file(
|
res = file_action(monitarr::utils::file::file(
|
||||||
monitarr::utils::path::combine(path, {de->d_name})));
|
monitarr::utils::path::combine(path, {de->d_name})));
|
||||||
@@ -105,8 +107,8 @@ auto traverse_directory(
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace monitarr::utils::file {
|
namespace monitarr::utils::file {
|
||||||
auto directory::copy_to(std::string_view new_path,
|
auto directory::copy_to(std::string_view new_path, bool overwrite) const
|
||||||
bool overwrite) const -> bool {
|
-> bool {
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -213,7 +215,7 @@ auto directory::exists() const -> bool {
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return ::PathIsDirectoryA(path_.c_str()) != 0;
|
return ::PathIsDirectoryA(path_.c_str()) != 0;
|
||||||
#else // !defined(_WIN32)
|
#else // !defined(_WIN32)
|
||||||
struct stat64 st {};
|
struct stat64 st{};
|
||||||
return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
@@ -266,8 +268,8 @@ auto directory::get_directories() const -> std::vector<fs_directory_t> {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto directory::create_file(std::string_view file_name,
|
auto directory::create_file(std::string_view file_name, bool read_only) const
|
||||||
bool read_only) const -> fs_file_t {
|
-> fs_file_t {
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ constexpr const auto file_type_count{3U};
|
|||||||
constexpr const auto file_type_count{2U};
|
constexpr const auto file_type_count{2U};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] auto create_file(auto idx, auto path,
|
[[nodiscard]] auto create_file(auto idx, auto path, bool read_only = false)
|
||||||
bool read_only = false) -> auto {
|
-> auto {
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
case 0U:
|
case 0U:
|
||||||
return monitarr::utils::file::file::open_or_create_file(path, read_only);
|
return monitarr::utils::file::file::open_or_create_file(path, read_only);
|
||||||
@@ -47,8 +47,8 @@ constexpr const auto file_type_count{2U};
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto open_file(auto idx, auto path,
|
[[nodiscard]] auto open_file(auto idx, auto path, bool read_only = false)
|
||||||
bool read_only = false) -> auto {
|
-> auto {
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
case 0U:
|
case 0U:
|
||||||
return monitarr::utils::file::file::open_file(path, read_only);
|
return monitarr::utils::file::file::open_file(path, read_only);
|
||||||
@@ -370,6 +370,41 @@ TEST(utils_file, directory_exists_in_path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(utils_file, directory_can_get_empty_directory_count) {
|
||||||
|
auto &test_dir = test::generate_test_directory();
|
||||||
|
EXPECT_EQ(0U, test_dir.count());
|
||||||
|
EXPECT_EQ(0U, test_dir.count(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(utils_file, directory_can_get_empty_directory_count_recursively) {
|
||||||
|
auto &test_dir = test::generate_test_directory();
|
||||||
|
EXPECT_EQ(0U, test_dir.count(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(utils_file, directory_can_get_non_empty_directory_count) {
|
||||||
|
auto &test_dir = test::generate_test_directory();
|
||||||
|
auto sub_dir = test_dir.create_directory("sub_dir");
|
||||||
|
EXPECT_TRUE(sub_dir != nullptr);
|
||||||
|
if (sub_dir) {
|
||||||
|
sub_dir->create_directory("sub_dir");
|
||||||
|
|
||||||
|
EXPECT_EQ(1U, test_dir.count());
|
||||||
|
EXPECT_EQ(1U, test_dir.count(false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(utils_file, directory_can_get_non_empty_directory_count_recursively) {
|
||||||
|
auto &test_dir = test::generate_test_directory();
|
||||||
|
auto sub_dir = test_dir.create_directory("sub_dir");
|
||||||
|
EXPECT_TRUE(sub_dir != nullptr);
|
||||||
|
if (sub_dir) {
|
||||||
|
sub_dir = sub_dir->create_directory("sub_dir");
|
||||||
|
EXPECT_TRUE(sub_dir != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_EQ(2U, test_dir.count(true));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(utils_file, file_exists_in_path) {
|
TEST(utils_file, file_exists_in_path) {
|
||||||
auto &test_dir = test::generate_test_directory();
|
auto &test_dir = test::generate_test_directory();
|
||||||
EXPECT_FALSE(
|
EXPECT_FALSE(
|
||||||
|
|||||||
Reference in New Issue
Block a user