updated build system
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-10-20 12:01:23 -05:00
parent 104e101158
commit 1f6036ec18
17 changed files with 696 additions and 705 deletions

View File

@ -92,11 +92,11 @@ template <typename val_t>
} }
if (fmt_val.empty()) { if (fmt_val.empty()) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"hex string is invalid", "hex string is invalid",
str, str,
}); });
} }
if (fmt_val.length() % 2U) { if (fmt_val.length() % 2U) {

View File

@ -101,10 +101,10 @@ public:
overloaded{ overloaded{
[](const data_type &value) -> data_type { return value; }, [](const data_type &value) -> data_type { return value; },
[](auto &&) -> data_type { [](auto &&) -> data_type {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"data type not supported", "data type not supported",
}); });
}, },
}, },
value_); value_);
@ -138,11 +138,11 @@ public:
} break; } break;
default: default:
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"column type not implemented", "column type not implemented",
std::to_string(column_type), std::to_string(column_type),
}); });
} }
columns_[name] = db_column{col, name, value}; columns_[name] = db_column{col, name, value};

View File

@ -124,10 +124,10 @@ encrypt_data(const std::array<unsigned char,
mac.data(), &mac_length, buffer, buffer_size, mac.data(), &mac_length, buffer, buffer_size,
reinterpret_cast<const unsigned char *>(&size), sizeof(size), nullptr, reinterpret_cast<const unsigned char *>(&size), sizeof(size), nullptr,
iv.data(), key.data()) != 0) { iv.data(), key.data()) != 0) {
throw repertory::utils::error::create_exception({ throw repertory::utils::error::create_exception(function_name,
function_name, {
"encryption failed", "encryption failed",
}); });
} }
std::memcpy(res.data(), iv.data(), iv.size()); std::memcpy(res.data(), iv.data(), iv.size());

View File

@ -29,7 +29,8 @@ namespace repertory::utils::error {
create_error_message(std::vector<std::string_view> items) -> std::string; create_error_message(std::vector<std::string_view> items) -> std::string;
[[nodiscard]] auto [[nodiscard]] auto
create_exception(std::vector<std::string_view> items) -> std::runtime_error; create_exception(std::string_view function_name,
std::vector<std::string_view> items) -> std::runtime_error;
struct i_exception_handler { struct i_exception_handler {
virtual ~i_exception_handler() {} virtual ~i_exception_handler() {}

View File

@ -92,32 +92,32 @@ auto create_hash_blake2b_t(const unsigned char *data,
crypto_generichash_blake2b_state state{}; crypto_generichash_blake2b_state state{};
auto res = crypto_generichash_blake2b_init(&state, nullptr, 0U, hash.size()); auto res = crypto_generichash_blake2b_init(&state, nullptr, 0U, hash.size());
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to initialize blake2b", "failed to initialize blake2b",
std::to_string(hash.size() * 8U), std::to_string(hash.size() * 8U),
std::to_string(res), std::to_string(res),
}); });
} }
res = crypto_generichash_blake2b_update(&state, data, data_size); res = crypto_generichash_blake2b_update(&state, data, data_size);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to update blake2b", "failed to update blake2b",
std::to_string(hash.size() * 8U), std::to_string(hash.size() * 8U),
std::to_string(res), std::to_string(res),
}); });
} }
res = crypto_generichash_blake2b_final(&state, hash.data(), hash.size()); res = crypto_generichash_blake2b_final(&state, hash.data(), hash.size());
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to finalize blake2b", "failed to finalize blake2b",
std::to_string(hash.size() * 8U), std::to_string(hash.size() * 8U),
std::to_string(res), std::to_string(res),
}); });
} }
return hash; return hash;

View File

@ -55,10 +55,10 @@ struct file_times final {
return written; return written;
} }
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"type_type not supported", "type_type not supported",
}); });
} }
}; };

View File

@ -87,12 +87,12 @@ auto create_db(std::string db_path,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr); SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
if (db_res != SQLITE_OK) { if (db_res != SQLITE_OK) {
const auto *msg = sqlite3_errstr(db_res); const auto *msg = sqlite3_errstr(db_res);
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to open db", "failed to open db",
db_path, db_path,
(msg == nullptr ? std::to_string(db_res) : msg), (msg == nullptr ? std::to_string(db_res) : msg),
}); });
} }
auto db3 = db3_t{ auto db3 = db3_t{
@ -104,10 +104,9 @@ auto create_db(std::string db_path,
std::string err_msg; std::string err_msg;
if (not sqlite::execute_sql(*db3, create_item.second, err_msg)) { if (not sqlite::execute_sql(*db3, create_item.second, err_msg)) {
db3.reset(); db3.reset();
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, err_msg,
err_msg, });
});
} }
} }

View File

@ -63,10 +63,10 @@ protected:
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if ((which & std::ios_base::in) != std::ios_base::in) { if ((which & std::ios_base::in) != std::ios_base::in) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"output is not supported", "output is not supported",
}); });
} }
const auto set_position = [this](char *next) -> pos_type { const auto set_position = [this](char *next) -> pos_type {
@ -187,11 +187,10 @@ encrypting_reader::encrypting_reader(
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not *source_file_) { if (not *source_file_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "file open failed",
"file open failed", source_path,
source_path, });
});
} }
data_buffer result; data_buffer result;
@ -214,11 +213,11 @@ encrypting_reader::encrypting_reader(
auto opt_size = source_file_->size(); auto opt_size = source_file_->size();
if (not opt_size.has_value()) { if (not opt_size.has_value()) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get file size", "failed to get file size",
source_file_->get_path(), source_file_->get_path(),
}); });
} }
auto file_size = opt_size.value(); auto file_size = opt_size.value();
@ -249,11 +248,10 @@ encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not *source_file_) { if (not *source_file_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "file open failed",
"file open failed", source_path,
source_path, });
});
} }
encrypted_file_path_ = encrypted_file_path; encrypted_file_path_ = encrypted_file_path;
@ -261,11 +259,11 @@ encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
auto opt_size = source_file_->size(); auto opt_size = source_file_->size();
if (not opt_size.has_value()) { if (not opt_size.has_value()) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get file size", "failed to get file size",
source_file_->get_path(), source_file_->get_path(),
}); });
} }
auto file_size = opt_size.value(); auto file_size = opt_size.value();
@ -298,11 +296,10 @@ encrypting_reader::encrypting_reader(
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not *source_file_) { if (not *source_file_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "file open failed",
"file open failed", source_path,
source_path, });
});
} }
encrypted_file_path_ = encrypted_file_path; encrypted_file_path_ = encrypted_file_path;
@ -310,12 +307,12 @@ encrypting_reader::encrypting_reader(
auto opt_size = source_file_->size(); auto opt_size = source_file_->size();
if (not opt_size.has_value()) { if (not opt_size.has_value()) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"get file size failed", "get file size failed",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
source_file_->get_path(), source_file_->get_path(),
}); });
} }
auto file_size{opt_size.value()}; auto file_size{opt_size.value()};
@ -347,12 +344,12 @@ encrypting_reader::encrypting_reader(const encrypting_reader &reader)
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not *source_file_) { if (not *source_file_) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"file open failed", "file open failed",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
source_file_->get_path(), source_file_->get_path(),
}); });
} }
} }
@ -370,12 +367,12 @@ auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
auto opt_size = utils::file::file{source_path}.size(); auto opt_size = utils::file::file{source_path}.size();
if (not opt_size.has_value()) { if (not opt_size.has_value()) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"get file size failed", "get file size failed",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
source_path, source_path,
}); });
} }
auto file_size{opt_size.value()}; auto file_size{opt_size.value()};

View File

@ -38,8 +38,10 @@ auto create_error_message(std::vector<std::string_view> items) -> std::string {
return stream.str(); return stream.str();
} }
auto create_exception(std::vector<std::string_view> items) auto create_exception(std::string_view function_name,
std::vector<std::string_view> items)
-> std::runtime_error { -> std::runtime_error {
items.insert(items.begin(), function_name);
return std::runtime_error(create_error_message(items)); return std::runtime_error(create_error_message(items));
} }

View File

@ -51,23 +51,23 @@ auto change_to_process_directory() -> bool {
#else // !defined(__APPLE__) #else // !defined(__APPLE__)
auto res = readlink("/proc/self/exe", path.data(), path.size()); auto res = readlink("/proc/self/exe", path.data(), path.size());
if (res == -1) { if (res == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to readlink", "failed to readlink",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
#endif // defined(__APPLE__) #endif // defined(__APPLE__)
path = utils::path::get_parent_path(path); path = utils::path::get_parent_path(path);
res = chdir(path.c_str()); res = chdir(path.c_str());
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to chdir", "failed to chdir",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
#endif // defined(_WIN32) #endif // defined(_WIN32)
@ -113,12 +113,12 @@ auto get_free_drive_space(std::string_view path)
ULARGE_INTEGER li{}; ULARGE_INTEGER li{};
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr, if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr,
nullptr)) { nullptr)) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get free disk space", "failed to get free disk space",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
return li.QuadPart; return li.QuadPart;
@ -127,12 +127,12 @@ auto get_free_drive_space(std::string_view path)
#if defined(__linux__) #if defined(__linux__)
struct statfs64 st {}; struct statfs64 st {};
if (statfs64(std::string{path}.c_str(), &st) != 0) { if (statfs64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get free disk space", "failed to get free disk space",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
return st.f_bfree * static_cast<std::uint64_t>(st.f_bsize); return st.f_bfree * static_cast<std::uint64_t>(st.f_bsize);
@ -141,12 +141,12 @@ auto get_free_drive_space(std::string_view path)
#if defined(__APPLE__) #if defined(__APPLE__)
struct statvfs st {}; struct statvfs st {};
if (statvfs(path.c_str(), &st) != 0) { if (statvfs(path.c_str(), &st) != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get free disk space", "failed to get free disk space",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
return st.f_bfree * static_cast<std::uint64_t>(st.f_frsize); return st.f_bfree * static_cast<std::uint64_t>(st.f_frsize);
@ -209,12 +209,12 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
struct _stat64 st {}; struct _stat64 st {};
if (_stat64(std::string{path}.c_str(), &st) != 0) { if (_stat64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get file times", "failed to get file times",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
ret.accessed = utils::time::windows_time_t_to_unix_time(st.st_atime); ret.accessed = utils::time::windows_time_t_to_unix_time(st.st_atime);
@ -224,12 +224,12 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
#else // !defined(_WIN32) #else // !defined(_WIN32)
struct stat64 st {}; struct stat64 st {};
if (stat64(std::string{path}.c_str(), &st) != 0) { if (stat64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get file times", "failed to get file times",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
ret.accessed = static_cast<std::uint64_t>(st.st_atim.tv_nsec) + ret.accessed = static_cast<std::uint64_t>(st.st_atim.tv_nsec) +
@ -270,12 +270,12 @@ auto get_total_drive_space(std::string_view path)
ULARGE_INTEGER li{}; ULARGE_INTEGER li{};
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li, if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li,
nullptr)) { nullptr)) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get total disk space", "failed to get total disk space",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
return li.QuadPart; return li.QuadPart;
@ -284,12 +284,12 @@ auto get_total_drive_space(std::string_view path)
#if defined(__linux__) #if defined(__linux__)
struct statfs64 st {}; struct statfs64 st {};
if (statfs64(std::string{path}.c_str(), &st) != 0) { if (statfs64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get total disk space", "failed to get total disk space",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
return st.f_blocks * static_cast<std::uint64_t>(st.f_bsize); return st.f_blocks * static_cast<std::uint64_t>(st.f_bsize);
@ -298,12 +298,12 @@ auto get_total_drive_space(std::string_view path)
#if defined(__APPLE__) #if defined(__APPLE__)
struct statvfs st {}; struct statvfs st {};
if (statvfs(path.c_str(), &st) != 0) { if (statvfs(path.c_str(), &st) != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get total disk space", "failed to get total disk space",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
return st.f_blocks * static_cast<std::uint64_t>(st.f_frsize); return st.f_blocks * static_cast<std::uint64_t>(st.f_frsize);
@ -424,12 +424,12 @@ auto write_json_file(std::string_view path,
try { try {
auto file = file::open_or_create_file(path); auto file = file::open_or_create_file(path);
if (not file->truncate()) { if (not file->truncate()) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to truncate file", "failed to truncate file",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
path, path,
}); });
} }
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) #if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
@ -503,11 +503,10 @@ auto smb_create_smb_path(std::string_view smb_path,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
std::string path{rel_path}; std::string path{rel_path};
@ -524,11 +523,10 @@ auto smb_create_smb_path(std::string_view smb_path,
path = "//" + utils::path::format_path(path, "/", "\\"); path = "//" + utils::path::format_path(path, "/", "\\");
if (not validate_smb_path(path)) { if (not validate_smb_path(path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", path,
path, });
});
} }
return path; return path;
@ -539,23 +537,22 @@ auto smb_create_and_validate_relative_path(
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
std::string dir_path; std::string dir_path;
if (utils::string::begins_with(path, "//")) { if (utils::string::begins_with(path, "//")) {
if (not utils::file::smb_parent_is_same(smb_path, path)) { if (not utils::file::smb_parent_is_same(smb_path, path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to validate path", "failed to validate path",
"parent paths are not the same", "parent paths are not the same",
smb_path, smb_path,
path, path,
}); });
} }
return utils::file::smb_create_relative_path(path); return utils::file::smb_create_relative_path(path);
@ -569,11 +566,10 @@ auto smb_create_relative_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
std::string path{smb_path}; std::string path{smb_path};
@ -589,11 +585,10 @@ auto smb_create_search_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
std::string path{smb_path}; std::string path{smb_path};
@ -610,11 +605,10 @@ auto smb_get_parent_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
auto parts = repertory::utils::string::split(smb_path.substr(2U), '/', false); auto parts = repertory::utils::string::split(smb_path.substr(2U), '/', false);
@ -624,11 +618,11 @@ auto smb_get_parent_path(std::string_view smb_path) -> std::string {
auto parent_smb_path = "//" + utils::string::join(parts, '/'); auto parent_smb_path = "//" + utils::string::join(parts, '/');
if (not validate_smb_path(parent_smb_path)) { if (not validate_smb_path(parent_smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"invalid parent smb path", "invalid parent smb path",
parent_smb_path, parent_smb_path,
}); });
} }
return parent_smb_path; return parent_smb_path;
@ -638,11 +632,10 @@ auto smb_get_root_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
auto parts = repertory::utils::string::split(smb_path.substr(2U), '/', false); auto parts = repertory::utils::string::split(smb_path.substr(2U), '/', false);
@ -657,11 +650,10 @@ auto smb_get_unc_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
std::string unc_path{smb_path}; std::string unc_path{smb_path};
@ -673,11 +665,10 @@ auto smb_get_uri_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
return "smb:" + std::string{smb_path}; return "smb:" + std::string{smb_path};
@ -688,11 +679,10 @@ auto smb_get_uri_path(std::string_view smb_path, std::string_view user,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) { if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "invalid smb path",
"invalid smb path", smb_path,
smb_path, });
});
} }
return "smb://" + std::string{user} + ':' + std::string{password} + '@' + return "smb://" + std::string{user} + ':' + std::string{password} + '@' +

View File

@ -46,12 +46,13 @@ auto traverse_directory(
auto search = repertory::utils::path::combine(path, {"*.*"}); auto search = repertory::utils::path::combine(path, {"*.*"});
auto find = ::FindFirstFileA(search.c_str(), &fd); auto find = ::FindFirstFileA(search.c_str(), &fd);
if (find == INVALID_HANDLE_VALUE) { if (find == INVALID_HANDLE_VALUE) {
throw repertory::utils::error::create_exception({ throw repertory::utils::error::create_exception(
function_name, function_name,
"failed to open directory", {
std::to_string(repertory::utils::get_last_error_code()), "failed to open directory",
path, std::to_string(repertory::utils::get_last_error_code()),
}); path,
});
} }
do { do {
@ -73,12 +74,13 @@ auto traverse_directory(
#else // !defined(_WIN32) #else // !defined(_WIN32)
auto *root = opendir(std::string{path}.c_str()); auto *root = opendir(std::string{path}.c_str());
if (root == nullptr) { if (root == nullptr) {
throw repertory::utils::error::create_exception({ throw repertory::utils::error::create_exception(
function_name, function_name,
"failed to open directory", {
std::to_string(repertory::utils::get_last_error_code()), "failed to open directory",
path, std::to_string(repertory::utils::get_last_error_code()),
}); path,
});
} }
struct dirent *de{nullptr}; struct dirent *de{nullptr};
@ -108,14 +110,14 @@ auto directory::copy_to(std::string_view new_path,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to copy directory", "failed to copy directory",
"not implemented", "not implemented",
utils::string::from_bool(overwrite), utils::string::from_bool(overwrite),
new_path, new_path,
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -171,12 +173,12 @@ auto directory::create_directory(std::string_view path) const
auto res = ::SHCreateDirectory(nullptr, auto res = ::SHCreateDirectory(nullptr,
utils::string::from_utf8(abs_path).c_str()); utils::string::from_utf8(abs_path).c_str());
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to create directory", "failed to create directory",
std::to_string(res), std::to_string(res),
abs_path, abs_path,
}); });
} }
#else // !defined(_WIN32) #else // !defined(_WIN32)
auto ret{true}; auto ret{true};
@ -377,13 +379,13 @@ auto directory::move_to(std::string_view new_path) -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to move directory", "failed to move directory",
"not implemented", "not implemented",
new_path, new_path,
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {

View File

@ -115,11 +115,10 @@ void file::open() {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not is_file(path_)) { if (not is_file(path_)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name, {
function_name, "file not found",
"file not found", path_,
path_, });
});
} }
#if defined(_WIN32) #if defined(_WIN32)
@ -300,20 +299,20 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
try { try {
if (not file_) { if (not file_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"file is not open for reading", "file is not open for reading",
path_, path_,
}); });
} }
if (fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET) == if (fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET) ==
-1) { -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to seek before read", "failed to seek before read",
path_, path_,
}); });
} }
std::size_t bytes_read{0U}; std::size_t bytes_read{0U};
@ -321,11 +320,11 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
auto res = auto res =
fread(&data[bytes_read], 1U, to_read - bytes_read, file_.get()); fread(&data[bytes_read], 1U, to_read - bytes_read, file_.get());
if (not feof(file_.get()) && ferror(file_.get())) { if (not feof(file_.get()) && ferror(file_.get())) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to read file bytes", "failed to read file bytes",
path_, path_,
}); });
} }
if (res == 0) { if (res == 0) {
@ -367,12 +366,12 @@ auto file::sha256() -> std::optional<std::string> {
crypto_hash_sha256_state state{}; crypto_hash_sha256_state state{};
auto res = crypto_hash_sha256_init(&state); auto res = crypto_hash_sha256_init(&state);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to initialize sha256", "failed to initialize sha256",
std::to_string(res), std::to_string(res),
path_, path_,
}); });
} }
{ {
@ -389,12 +388,12 @@ auto file::sha256() -> std::optional<std::string> {
&state, reinterpret_cast<const unsigned char *>(buffer.data()), &state, reinterpret_cast<const unsigned char *>(buffer.data()),
bytes_read); bytes_read);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to update sha256", "failed to update sha256",
std::to_string(res), std::to_string(res),
path_, path_,
}); });
} }
} }
} }
@ -402,12 +401,12 @@ auto file::sha256() -> std::optional<std::string> {
std::array<unsigned char, crypto_hash_sha256_BYTES> out{}; std::array<unsigned char, crypto_hash_sha256_BYTES> out{};
res = crypto_hash_sha256_final(&state, out.data()); res = crypto_hash_sha256_final(&state, out.data());
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to finalize sha256", "failed to finalize sha256",
std::to_string(res), std::to_string(res),
path_, path_,
}); });
} }
ret = utils::collection::to_hex_string(out); ret = utils::collection::to_hex_string(out);
@ -497,20 +496,20 @@ auto file::write(const unsigned char *data, std::size_t to_write,
try { try {
if (not file_) { if (not file_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"file is not open for writing", "file is not open for writing",
path_, path_,
}); });
} }
auto res = fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET); auto res = fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET);
if (res == -1) { if (res == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to seek before write", "failed to seek before write",
path_, path_,
}); });
} }
std::size_t bytes_written{0U}; std::size_t bytes_written{0U};
@ -519,11 +518,11 @@ auto file::write(const unsigned char *data, std::size_t to_write,
fwrite(reinterpret_cast<const char *>(&data[bytes_written]), 1U, fwrite(reinterpret_cast<const char *>(&data[bytes_written]), 1U,
to_write - bytes_written, file_.get()); to_write - bytes_written, file_.get());
if (not feof(file_.get()) && ferror(file_.get())) { if (not feof(file_.get()) && ferror(file_.get())) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to write file bytes", "failed to write file bytes",
path_, path_,
}); });
} }
if (written == 0U) { if (written == 0U) {
@ -555,20 +554,20 @@ auto file::size() const -> std::optional<std::uint64_t> {
try { try {
if (file_) { if (file_) {
if (fseeko(file_.get(), 0, SEEK_END) == -1) { if (fseeko(file_.get(), 0, SEEK_END) == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to seek", "failed to seek",
path_, path_,
}); });
} }
auto size = ftello(file_.get()); auto size = ftello(file_.get());
if (size == -1) { if (size == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get position", "failed to get position",
path_, path_,
}); });
} }
return static_cast<std::uint64_t>(size); return static_cast<std::uint64_t>(size);
@ -576,11 +575,11 @@ auto file::size() const -> std::optional<std::uint64_t> {
std::uint64_t size{}; std::uint64_t size{};
if (not get_file_size(path_, size)) { if (not get_file_size(path_, size)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get file size", "failed to get file size",
path_, path_,
}); });
} }
return size; return size;

View File

@ -52,12 +52,12 @@ auto smb_directory::open(std::string_view host, std::string_view user,
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
res = inet_pton(AF_INET, std::string{host}.c_str(), &addr.sin_addr); res = inet_pton(AF_INET, std::string{host}.c_str(), &addr.sin_addr);
if (res != 1) { if (res != 1) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to resolve host", "failed to resolve host",
std::to_string(utils::get_last_error_code()), std::to_string(utils::get_last_error_code()),
host, host,
}); });
} }
} }
@ -65,12 +65,12 @@ auto smb_directory::open(std::string_view host, std::string_view user,
static_cast<std::uint32_t>(addr.sin_addr.s_addr), static_cast<std::uint32_t>(addr.sin_addr.s_addr),
SMB_TRANSPORT_TCP); SMB_TRANSPORT_TCP);
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to connect to host", "failed to connect to host",
std::to_string(res), std::to_string(res),
host, host,
}); });
} }
smb_session_set_creds(session.get(), std::string{host}.c_str(), smb_session_set_creds(session.get(), std::string{host}.c_str(),
@ -78,13 +78,13 @@ auto smb_directory::open(std::string_view host, std::string_view user,
std::string{password}.c_str()); std::string{password}.c_str());
res = smb_session_login(session.get()); res = smb_session_login(session.get());
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to logon to host", "failed to logon to host",
std::to_string(res), std::to_string(res),
host, host,
user, user,
}); });
} }
auto share_name = utils::string::split(path, '/', false).at(0U); auto share_name = utils::string::split(path, '/', false).at(0U);
@ -92,12 +92,12 @@ auto smb_directory::open(std::string_view host, std::string_view user,
smb_tid tid{}; smb_tid tid{};
res = smb_tree_connect(session.get(), share_name.c_str(), &tid); res = smb_tree_connect(session.get(), share_name.c_str(), &tid);
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to connect to share", "failed to connect to share",
std::to_string(res), std::to_string(res),
share_name, share_name,
}); });
} }
return smb_directory_t{ return smb_directory_t{
@ -132,22 +132,22 @@ auto smb_directory::copy_to(std::string_view new_path,
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
// auto to_path = utils::path::absolute(new_path); // auto to_path = utils::path::absolute(new_path);
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to copy directory", "failed to copy directory",
"not implemented", "not implemented",
new_path, new_path,
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -162,11 +162,11 @@ auto smb_directory::count(bool recursive) const -> std::uint64_t {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
smb_stat_list_t list{ smb_stat_list_t list{
@ -179,13 +179,13 @@ auto smb_directory::count(bool recursive) const -> std::uint64_t {
return count; return count;
} }
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to get directory count recursively", "failed to get directory count recursively",
"not implemented", "not implemented",
utils::string::from_bool(recursive), utils::string::from_bool(recursive),
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -201,11 +201,11 @@ auto smb_directory::create_directory(std::string_view path) const
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
auto dir = get_directory(path); auto dir = get_directory(path);
@ -217,12 +217,12 @@ auto smb_directory::create_directory(std::string_view path) const
session_.get(), tid_, session_.get(), tid_,
smb_create_and_validate_relative_path(path_, path).c_str()); smb_create_and_validate_relative_path(path_, path).c_str());
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to create directory", "failed to create directory",
std::to_string(res), std::to_string(res),
path_, path_,
}); });
} }
return get_directory(path); return get_directory(path);
@ -241,21 +241,21 @@ auto smb_directory::create_file(std::string_view file_name,
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
auto fs_file = get_file(file_name); auto fs_file = get_file(file_name);
if (fs_file) { if (fs_file) {
if (not dynamic_cast<smb_file *>(fs_file.get())->open(read_only)) { if (not dynamic_cast<smb_file *>(fs_file.get())->open(read_only)) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to open existing file", "failed to open existing file",
file_name, file_name,
}); });
} }
return fs_file; return fs_file;
@ -293,11 +293,11 @@ auto smb_directory::exists() const -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
smb_stat_t st{ smb_stat_t st{
@ -325,11 +325,11 @@ auto smb_directory::get_directory(std::string_view path) const
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
auto rel_path = smb_create_and_validate_relative_path(path_, path); auto rel_path = smb_create_and_validate_relative_path(path_, path);
@ -338,22 +338,22 @@ auto smb_directory::get_directory(std::string_view path) const
smb_stat_deleter(), smb_stat_deleter(),
}; };
if (not st) { if (not st) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to stat directory", "failed to stat directory",
rel_path, rel_path,
path_, path_,
}); });
} }
bool is_dir{smb_stat_get(st.get(), SMB_STAT_ISDIR) != 0U}; bool is_dir{smb_stat_get(st.get(), SMB_STAT_ISDIR) != 0U};
if (not is_dir) { if (not is_dir) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"path is not a directory", "path is not a directory",
rel_path, rel_path,
path_, path_,
}); });
} }
return smb_directory_t{ return smb_directory_t{
@ -379,11 +379,11 @@ auto smb_directory::get_directories() const -> std::vector<fs_directory_t> {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
smb_stat_list_t list{ smb_stat_list_t list{
smb_find(session_.get(), tid_, smb_create_search_path(path_).c_str()), smb_find(session_.get(), tid_, smb_create_search_path(path_).c_str()),
@ -391,11 +391,11 @@ auto smb_directory::get_directories() const -> std::vector<fs_directory_t> {
smb_stat_list_deleter(), smb_stat_list_deleter(),
}; };
if (not list) { if (not list) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get directory list", "failed to get directory list",
path_, path_,
}); });
} }
std::vector<fs_directory_t> ret{}; std::vector<fs_directory_t> ret{};
@ -446,11 +446,11 @@ auto smb_directory::get_file(std::string_view path) const -> fs_file_t {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
auto rel_path = smb_create_and_validate_relative_path(path_, path); auto rel_path = smb_create_and_validate_relative_path(path_, path);
@ -459,22 +459,22 @@ auto smb_directory::get_file(std::string_view path) const -> fs_file_t {
smb_stat_deleter(), smb_stat_deleter(),
}; };
if (not st) { if (not st) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to stat file", "failed to stat file",
rel_path, rel_path,
path_, path_,
}); });
} }
bool is_dir{smb_stat_get(st.get(), SMB_STAT_ISDIR) != 0U}; bool is_dir{smb_stat_get(st.get(), SMB_STAT_ISDIR) != 0U};
if (is_dir) { if (is_dir) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"path is not a file", "path is not a file",
rel_path, rel_path,
path_, path_,
}); });
} }
return std::make_unique<smb_file>( return std::make_unique<smb_file>(
@ -494,11 +494,11 @@ auto smb_directory::get_files() const -> std::vector<fs_file_t> {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
smb_stat_list_t list{ smb_stat_list_t list{
@ -506,11 +506,11 @@ auto smb_directory::get_files() const -> std::vector<fs_file_t> {
smb_stat_list_deleter(), smb_stat_list_deleter(),
}; };
if (not list) { if (not list) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get file list", "failed to get file list",
path_, path_,
}); });
} }
std::vector<fs_file_t> ret{}; std::vector<fs_file_t> ret{};
@ -551,11 +551,11 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
smb_stat_list_t list{ smb_stat_list_t list{
@ -563,11 +563,11 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
smb_stat_list_deleter(), smb_stat_list_deleter(),
}; };
if (not list) { if (not list) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get item list", "failed to get item list",
path_, path_,
}); });
} }
std::vector<fs_item_t> ret{}; std::vector<fs_item_t> ret{};
@ -636,11 +636,11 @@ auto smb_directory::is_symlink() const -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
} catch (const std::exception &e) { } catch (const std::exception &e) {
@ -657,20 +657,20 @@ auto smb_directory::move_to(std::string_view new_path) -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to move directory", "failed to move directory",
"not implemented", "not implemented",
new_path, new_path,
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -685,11 +685,11 @@ auto smb_directory::remove() -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
return utils::retry_action([this]() -> bool { return utils::retry_action([this]() -> bool {
@ -701,12 +701,12 @@ auto smb_directory::remove() -> bool {
auto res = smb_directory_rm(session_.get(), tid_, auto res = smb_directory_rm(session_.get(), tid_,
smb_create_relative_path(path_).c_str()); smb_create_relative_path(path_).c_str());
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to remove directory", "failed to remove directory",
std::to_string(res), std::to_string(res),
path_, path_,
}); });
} }
return true; return true;
@ -732,23 +732,23 @@ auto smb_directory::remove_recursively() -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
if (not exists()) { if (not exists()) {
return true; return true;
} }
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to remove directory recursively", "failed to remove directory recursively",
"not implemented", "not implemented",
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -763,19 +763,19 @@ auto smb_directory::size(bool /* recursive */) const -> std::uint64_t {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to get directory size", "failed to get directory size",
"not implemented", "not implemented",
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {

View File

@ -41,23 +41,23 @@ auto smb_file::copy_to(std::string_view new_path,
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
// auto to_path = utils::path::absolute(new_path); // auto to_path = utils::path::absolute(new_path);
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to copy file", "failed to copy file",
"not implemented", "not implemented",
std::to_string(overwrite), std::to_string(overwrite),
new_path, new_path,
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -72,11 +72,11 @@ auto smb_file::exists() const -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
smb_stat_t st{ smb_stat_t st{
@ -102,12 +102,12 @@ void smb_file::flush() const {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to flush file", "failed to flush file",
"not implemented", "not implemented",
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -121,11 +121,11 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
try { try {
if (session == nullptr) { if (session == nullptr) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path, path,
}); });
} }
auto rel_path = smb_create_relative_path(path); auto rel_path = smb_create_relative_path(path);
@ -134,13 +134,13 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
smb_stat_deleter(), smb_stat_deleter(),
}; };
if (not st) { if (not st) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to stat file", "failed to stat file",
"not implemented", "not implemented",
rel_path, rel_path,
path, path,
}); });
} }
switch (type) { switch (type) {
@ -170,11 +170,11 @@ auto smb_file::is_symlink() const -> bool {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
} catch (const std::exception &e) { } catch (const std::exception &e) {
@ -191,13 +191,13 @@ auto smb_file::move_to(std::string_view new_path) -> bool {
try { try {
if (utils::string::begins_with(new_path, "//")) { if (utils::string::begins_with(new_path, "//")) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to move file", "failed to move file",
"new path must be in same share", "new path must be in same share",
new_path, new_path,
path_, path_,
}); });
} }
auto from_path = smb_create_relative_path(path_); auto from_path = smb_create_relative_path(path_);
@ -214,24 +214,24 @@ auto smb_file::move_to(std::string_view new_path) -> bool {
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_); auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to connect to share", "failed to connect to share",
std::to_string(res), std::to_string(res),
share_name_, share_name_,
path_, path_,
}); });
} }
res = smb_file_mv(session_.get(), tid_, from_path.c_str(), to_path.c_str()); res = smb_file_mv(session_.get(), tid_, from_path.c_str(), to_path.c_str());
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to move file", "failed to move file",
std::to_string(res), std::to_string(res),
from_path, from_path,
to_path, to_path,
}); });
} }
path_ = smb_create_smb_path(path_, to_path); path_ = smb_create_smb_path(path_, to_path);
@ -265,27 +265,27 @@ auto smb_file::open(bool read_only) -> bool {
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_); auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to connect to share", "failed to connect to share",
std::to_string(res), std::to_string(res),
share_name_, share_name_,
path_, path_,
}); });
} }
smb_fd fd{}; smb_fd fd{};
res = smb_fopen(session_.get(), tid_, rel_path.c_str(), res = smb_fopen(session_.get(), tid_, rel_path.c_str(),
read_only ? SMB_MOD_RO : SMB_MOD_RW2, &fd); read_only ? SMB_MOD_RO : SMB_MOD_RW2, &fd);
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"failed to open file", "failed to open file",
std::to_string(res), std::to_string(res),
utils::string::from_bool(read_only), utils::string::from_bool(read_only),
rel_path, rel_path,
path_, path_,
}); });
} }
fd_ = fd; fd_ = fd;
@ -311,24 +311,24 @@ auto smb_file::read(unsigned char *data, std::size_t to_read,
} }
if (not fd_.has_value()) { if (not fd_.has_value()) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to read file", "failed to read file",
"file not open", "file not open",
path_, path_,
}); });
} }
auto res = smb_fseek(session_.get(), *fd_, static_cast<off_t>(offset), auto res = smb_fseek(session_.get(), *fd_, static_cast<off_t>(offset),
SMB_SEEK_SET); SMB_SEEK_SET);
if (res == -1) { if (res == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to seek file", "failed to seek file",
std::to_string(res), std::to_string(res),
std::to_string(offset), std::to_string(offset),
path_, path_,
}); });
} }
std::size_t bytes_read{0U}; std::size_t bytes_read{0U};
@ -336,14 +336,14 @@ auto smb_file::read(unsigned char *data, std::size_t to_read,
res = smb_fread(session_.get(), *fd_, &data[bytes_read], res = smb_fread(session_.get(), *fd_, &data[bytes_read],
to_read - bytes_read); to_read - bytes_read);
if (res == -1) { if (res == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to read file", "failed to read file",
std::to_string(res), std::to_string(res),
std::to_string(offset), std::to_string(offset),
std::to_string(to_read), std::to_string(to_read),
path_, path_,
}); });
} }
if (res == 0) { if (res == 0) {
@ -381,26 +381,27 @@ auto smb_file::remove() -> bool {
try { try {
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_); auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to connect to share", "failed to connect to share",
std::to_string(res), std::to_string(res),
share_name_, share_name_,
path_, path_,
}); });
} }
auto rel_path = smb_create_relative_path(path_); auto rel_path = smb_create_relative_path(path_);
res = smb_file_rm(session_.get(), tid_, rel_path.c_str()); res = smb_file_rm(session_.get(), tid_, rel_path.c_str());
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name,
"failed to remove file", {
std::to_string(res), "failed to remove file",
std::to_string(smb_session_get_nt_status(session_.get())), std::to_string(res),
rel_path, std::to_string(smb_session_get_nt_status(session_.get())),
path_, rel_path,
}); path_,
});
} }
return true; return true;
@ -426,11 +427,11 @@ auto smb_file::size() const -> std::optional<std::uint64_t> {
try { try {
if (not session_) { if (not session_) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"session not found", "session not found",
path_, path_,
}); });
} }
auto rel_path = smb_create_relative_path(path_); auto rel_path = smb_create_relative_path(path_);
@ -439,12 +440,12 @@ auto smb_file::size() const -> std::optional<std::uint64_t> {
smb_stat_deleter(), smb_stat_deleter(),
}; };
if (not st) { if (not st) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to stat directory", "failed to stat directory",
rel_path, rel_path,
path_, path_,
}); });
} }
return smb_stat_get(st.get(), SMB_STAT_SIZE); return smb_stat_get(st.get(), SMB_STAT_SIZE);
@ -461,13 +462,13 @@ auto smb_file::truncate(std::size_t size) -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to truncate file", "failed to truncate file",
"not implemented", "not implemented",
std::to_string(size), std::to_string(size),
path_, path_,
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
@ -487,24 +488,24 @@ auto smb_file::write(const unsigned char *data, std::size_t to_write,
} }
if (not fd_.has_value()) { if (not fd_.has_value()) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to write file", "failed to write file",
"file not open", "file not open",
path_, path_,
}); });
} }
auto res = smb_fseek(session_.get(), *fd_, static_cast<off_t>(offset), auto res = smb_fseek(session_.get(), *fd_, static_cast<off_t>(offset),
SMB_SEEK_SET); SMB_SEEK_SET);
if (res == -1) { if (res == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to seek file", "failed to seek file",
std::to_string(res), std::to_string(res),
std::to_string(offset), std::to_string(offset),
path_, path_,
}); });
} }
std::size_t bytes_written{0U}; std::size_t bytes_written{0U};
@ -513,14 +514,14 @@ auto smb_file::write(const unsigned char *data, std::size_t to_write,
const_cast<unsigned char *>(&data[bytes_written]), const_cast<unsigned char *>(&data[bytes_written]),
to_write - bytes_written); to_write - bytes_written);
if (res == -1) { if (res == -1) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to write file", "failed to write file",
std::to_string(res), std::to_string(res),
std::to_string(offset), std::to_string(offset),
std::to_string(to_write), std::to_string(to_write),
path_, path_,
}); });
} }
if (res == 0) { if (res == 0) {

View File

@ -120,29 +120,29 @@ auto create_hash_sha512(const unsigned char *data,
crypto_hash_sha512_state state{}; crypto_hash_sha512_state state{};
auto res = crypto_hash_sha512_init(&state); auto res = crypto_hash_sha512_init(&state);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to initialize sha-512", "failed to initialize sha-512",
std::to_string(res), std::to_string(res),
}); });
} }
res = crypto_hash_sha512_update(&state, data, data_size); res = crypto_hash_sha512_update(&state, data, data_size);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to update sha-512", "failed to update sha-512",
std::to_string(res), std::to_string(res),
}); });
} }
res = crypto_hash_sha512_final(&state, hash.data()); res = crypto_hash_sha512_final(&state, hash.data());
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to finalize sha-512", "failed to finalize sha-512",
std::to_string(res), std::to_string(res),
}); });
} }
return hash; return hash;
@ -157,29 +157,29 @@ auto create_hash_sha256(const unsigned char *data,
crypto_hash_sha256_state state{}; crypto_hash_sha256_state state{};
auto res = crypto_hash_sha256_init(&state); auto res = crypto_hash_sha256_init(&state);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to initialize sha-256", "failed to initialize sha-256",
std::to_string(res), std::to_string(res),
}); });
} }
res = crypto_hash_sha256_update(&state, data, data_size); res = crypto_hash_sha256_update(&state, data, data_size);
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to update sha-256", "failed to update sha-256",
std::to_string(res), std::to_string(res),
}); });
} }
res = crypto_hash_sha256_final(&state, hash.data()); res = crypto_hash_sha256_final(&state, hash.data());
if (res != 0) { if (res != 0) {
throw utils::error::create_exception({ throw utils::error::create_exception(function_name,
function_name, {
"failed to finalize sha-256", "failed to finalize sha-256",
std::to_string(res), std::to_string(res),
}); });
} }
return hash; return hash;

View File

@ -65,11 +65,11 @@ namespace {
} }
}); });
if (res) { if (res) {
throw repertory::utils::error::create_exception({ throw repertory::utils::error::create_exception(function_name,
function_name, {
"failed to getpwuid", "failed to getpwuid",
res.reason, res.reason,
}); });
} }
path = repertory::utils::string::replace(path, "~/", home + "/"); path = repertory::utils::string::replace(path, "~/", home + "/");

View File

@ -74,10 +74,10 @@ auto get_local_app_data_directory() -> const std::string & {
return ret; return ret;
} }
throw utils::error::create_exception({ throw utils::error::create_exception(
function_name, function_name, {
"unable to detect local application data folder", "unable to detect local application data folder",
}); });
})(); })();
return app_data; return app_data;