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,8 +92,8 @@ template <typename val_t>
}
if (fmt_val.empty()) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name,
{
"hex string is invalid",
str,
});

View File

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

View File

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

View File

@ -29,7 +29,8 @@ namespace repertory::utils::error {
create_error_message(std::vector<std::string_view> items) -> std::string;
[[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 {
virtual ~i_exception_handler() {}

View File

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

View File

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

View File

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

View File

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

View File

@ -38,8 +38,10 @@ auto create_error_message(std::vector<std::string_view> items) -> std::string {
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 {
items.insert(items.begin(), function_name);
return std::runtime_error(create_error_message(items));
}

View File

@ -51,8 +51,8 @@ auto change_to_process_directory() -> bool {
#else // !defined(__APPLE__)
auto res = readlink("/proc/self/exe", path.data(), path.size());
if (res == -1) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to readlink",
std::to_string(utils::get_last_error_code()),
path,
@ -62,8 +62,8 @@ auto change_to_process_directory() -> bool {
path = utils::path::get_parent_path(path);
res = chdir(path.c_str());
if (res != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to chdir",
std::to_string(utils::get_last_error_code()),
path,
@ -113,8 +113,8 @@ auto get_free_drive_space(std::string_view path)
ULARGE_INTEGER li{};
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr,
nullptr)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get free disk space",
std::to_string(utils::get_last_error_code()),
path,
@ -127,8 +127,8 @@ auto get_free_drive_space(std::string_view path)
#if defined(__linux__)
struct statfs64 st {};
if (statfs64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get free disk space",
std::to_string(utils::get_last_error_code()),
path,
@ -141,8 +141,8 @@ auto get_free_drive_space(std::string_view path)
#if defined(__APPLE__)
struct statvfs st {};
if (statvfs(path.c_str(), &st) != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get free disk space",
std::to_string(utils::get_last_error_code()),
path,
@ -209,8 +209,8 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
struct _stat64 st {};
if (_stat64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get file times",
std::to_string(utils::get_last_error_code()),
path,
@ -224,8 +224,8 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
#else // !defined(_WIN32)
struct stat64 st {};
if (stat64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get file times",
std::to_string(utils::get_last_error_code()),
path,
@ -270,8 +270,8 @@ auto get_total_drive_space(std::string_view path)
ULARGE_INTEGER li{};
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li,
nullptr)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get total disk space",
std::to_string(utils::get_last_error_code()),
path,
@ -284,8 +284,8 @@ auto get_total_drive_space(std::string_view path)
#if defined(__linux__)
struct statfs64 st {};
if (statfs64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get total disk space",
std::to_string(utils::get_last_error_code()),
path,
@ -298,8 +298,8 @@ auto get_total_drive_space(std::string_view path)
#if defined(__APPLE__)
struct statvfs st {};
if (statvfs(path.c_str(), &st) != 0) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to get total disk space",
std::to_string(utils::get_last_error_code()),
path,
@ -424,8 +424,8 @@ auto write_json_file(std::string_view path,
try {
auto file = file::open_or_create_file(path);
if (not file->truncate()) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(
function_name, {
"failed to truncate file",
std::to_string(utils::get_last_error_code()),
path,
@ -503,8 +503,7 @@ auto smb_create_smb_path(std::string_view smb_path,
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -524,8 +523,7 @@ auto smb_create_smb_path(std::string_view smb_path,
path = "//" + utils::path::format_path(path, "/", "\\");
if (not validate_smb_path(path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
path,
});
@ -539,8 +537,7 @@ auto smb_create_and_validate_relative_path(
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -549,8 +546,8 @@ auto smb_create_and_validate_relative_path(
std::string dir_path;
if (utils::string::begins_with(path, "//")) {
if (not utils::file::smb_parent_is_same(smb_path, path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name,
{
"failed to validate path",
"parent paths are not the same",
smb_path,
@ -569,8 +566,7 @@ auto smb_create_relative_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -589,8 +585,7 @@ auto smb_create_search_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -610,8 +605,7 @@ auto smb_get_parent_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -624,8 +618,8 @@ auto smb_get_parent_path(std::string_view smb_path) -> std::string {
auto parent_smb_path = "//" + utils::string::join(parts, '/');
if (not validate_smb_path(parent_smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name,
{
"invalid parent smb path",
parent_smb_path,
});
@ -638,8 +632,7 @@ auto smb_get_root_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -657,8 +650,7 @@ auto smb_get_unc_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -673,8 +665,7 @@ auto smb_get_uri_path(std::string_view smb_path) -> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});
@ -688,8 +679,7 @@ auto smb_get_uri_path(std::string_view smb_path, std::string_view user,
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
throw utils::error::create_exception({
function_name,
throw utils::error::create_exception(function_name, {
"invalid smb path",
smb_path,
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,8 +65,8 @@ namespace {
}
});
if (res) {
throw repertory::utils::error::create_exception({
function_name,
throw repertory::utils::error::create_exception(function_name,
{
"failed to getpwuid",
res.reason,
});

View File

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