updated build system
Some checks failed
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
Some checks failed
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
@@ -41,14 +41,23 @@ auto smb_file::copy_to(std::string_view new_path,
|
||||
|
||||
try {
|
||||
if (not session_) {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"session not found",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
// auto to_path = utils::path::absolute(new_path);
|
||||
|
||||
throw std::runtime_error("failed to copy file|" + path_ + '|' +
|
||||
std::string{new_path} + '|' +
|
||||
std::to_string(overwrite) + "|not implemented");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to copy file",
|
||||
"not implemented",
|
||||
std::to_string(overwrite),
|
||||
path_,
|
||||
new_path,
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
@@ -63,7 +72,11 @@ auto smb_file::exists() const -> bool {
|
||||
|
||||
try {
|
||||
if (not session_) {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"session not found",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
smb_stat_t st{
|
||||
@@ -89,8 +102,12 @@ void smb_file::flush() const {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
throw std::runtime_error("failed to flush file|" + path_ +
|
||||
"|not implemented");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to flush file",
|
||||
"not implemented",
|
||||
path_,
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
@@ -104,7 +121,11 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
|
||||
|
||||
try {
|
||||
if (session == nullptr) {
|
||||
throw std::runtime_error("session not found|" + path);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"session not found",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path);
|
||||
@@ -113,7 +134,12 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to stat file",
|
||||
"not implemented",
|
||||
rel_path,
|
||||
});
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@@ -143,7 +169,11 @@ auto smb_file::is_symlink() const -> bool {
|
||||
|
||||
try {
|
||||
if (not session_) {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"session not found",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
@@ -160,9 +190,13 @@ auto smb_file::move_to(std::string_view new_path) -> bool {
|
||||
|
||||
try {
|
||||
if (utils::string::begins_with(new_path, "//")) {
|
||||
throw std::runtime_error("failed to move file|" + path_ + '|' +
|
||||
std::string{new_path} +
|
||||
"|new path must be in same share");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to move file",
|
||||
"new path must be in same share",
|
||||
path_,
|
||||
new_path,
|
||||
});
|
||||
}
|
||||
|
||||
auto from_path = smb_create_relative_path(path_);
|
||||
@@ -179,15 +213,23 @@ 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 std::runtime_error("failed to connect to share|" + share_name_ +
|
||||
'|' + std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to connect to share",
|
||||
path_std::to_string(res),
|
||||
share_name_,
|
||||
});
|
||||
}
|
||||
|
||||
res = smb_file_mv(session_.get(), tid_, from_path.c_str(), to_path.c_str());
|
||||
if (res != DSM_SUCCESS) {
|
||||
throw std::runtime_error("failed to move file|" + path_ + '|' +
|
||||
from_path + '|' + to_path + '|' +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to move file",
|
||||
path_std::to_string(res),
|
||||
from_path,
|
||||
to_path,
|
||||
});
|
||||
}
|
||||
|
||||
path_ = smb_create_smb_path(path_, to_path);
|
||||
@@ -221,17 +263,26 @@ 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 std::runtime_error("failed to connect to share|" + share_name_ +
|
||||
'|' + std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to connect to share",
|
||||
path_std::to_string(res),
|
||||
share_name_,
|
||||
});
|
||||
}
|
||||
|
||||
smb_fd fd{};
|
||||
res = smb_fopen(session_.get(), tid_, rel_path.c_str(),
|
||||
read_only ? SMB_MOD_RO : SMB_MOD_RW2, &fd);
|
||||
if (res != DSM_SUCCESS) {
|
||||
throw std::runtime_error("failed to open file|" + path_ + '|' + rel_path +
|
||||
'|' + utils::string::from_bool(read_only) + '|' +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to open file",
|
||||
utils::string::from_bool(read_only),
|
||||
path_std::to_string(res),
|
||||
path_,
|
||||
rel_path,
|
||||
});
|
||||
}
|
||||
|
||||
fd_ = fd;
|
||||
@@ -257,16 +308,24 @@ auto smb_file::read(unsigned char *data, std::size_t to_read,
|
||||
}
|
||||
|
||||
if (not fd_.has_value()) {
|
||||
throw std::runtime_error("failed to read file|" + path_ +
|
||||
"|file not open");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to read file",
|
||||
"file not open",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
auto res = smb_fseek(session_.get(), *fd_, static_cast<off_t>(offset),
|
||||
SMB_SEEK_SET);
|
||||
if (res == -1) {
|
||||
throw std::runtime_error("failed to seek file|" + path_ + '|' +
|
||||
std::to_string(offset) + '|' +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to seek file",
|
||||
std::to_string(res),
|
||||
std::to_string(offset),
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
std::size_t bytes_read{0U};
|
||||
@@ -274,9 +333,14 @@ 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 std::runtime_error("failed to read file|" + path_ + '|' +
|
||||
std::to_string(to_read) + '|' +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to read file",
|
||||
std::to_string(res),
|
||||
std::to_string(offset),
|
||||
std::to_string(to_read),
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
@@ -314,17 +378,25 @@ auto smb_file::remove() -> bool {
|
||||
try {
|
||||
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
|
||||
if (res != DSM_SUCCESS) {
|
||||
throw std::runtime_error("failed to connect to share|" + share_name_ +
|
||||
'|' + std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to connect to share",
|
||||
path_std::to_string(res),
|
||||
share_name_,
|
||||
});
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path_);
|
||||
res = smb_file_rm(session_.get(), tid_, rel_path.c_str());
|
||||
if (res != DSM_SUCCESS) {
|
||||
throw std::runtime_error(
|
||||
"failed to remove file|" + path_ + '|' + rel_path + '|' +
|
||||
std::to_string(res) + '|' +
|
||||
std::to_string(smb_session_get_nt_status(session_.get())));
|
||||
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())),
|
||||
path_,
|
||||
rel_path,
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -350,7 +422,11 @@ auto smb_file::size() const -> std::optional<std::uint64_t> {
|
||||
|
||||
try {
|
||||
if (not session_) {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"session not found",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path_);
|
||||
@@ -359,7 +435,11 @@ auto smb_file::size() const -> std::optional<std::uint64_t> {
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to stat directory",
|
||||
rel_path,
|
||||
});
|
||||
}
|
||||
|
||||
return smb_stat_get(st.get(), SMB_STAT_SIZE);
|
||||
@@ -376,8 +456,13 @@ auto smb_file::truncate(std::size_t size) -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
throw std::runtime_error("failed to truncate file|" + path_ + '|' +
|
||||
std::to_string(size) + "|not implemented");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to truncate file",
|
||||
"not implemented",
|
||||
std::to_string(size),
|
||||
path_,
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
@@ -397,16 +482,24 @@ auto smb_file::write(const unsigned char *data, std::size_t to_write,
|
||||
}
|
||||
|
||||
if (not fd_.has_value()) {
|
||||
throw std::runtime_error("failed to write file|" + path_ +
|
||||
"|file not open");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to write file",
|
||||
"file not open",
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
auto res = smb_fseek(session_.get(), *fd_, static_cast<off_t>(offset),
|
||||
SMB_SEEK_SET);
|
||||
if (res == -1) {
|
||||
throw std::runtime_error("failed to seek file|" + path_ + '|' +
|
||||
std::to_string(offset) + '|' +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to seek file",
|
||||
std::to_string(res),
|
||||
std::to_string(offset),
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
std::size_t bytes_written{0U};
|
||||
@@ -415,9 +508,14 @@ 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 std::runtime_error("failed to write file|" + path_ + '|' +
|
||||
std::to_string(to_write) + '|' +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to write file",
|
||||
std::to_string(res),
|
||||
std::to_string(offset),
|
||||
std::to_string(to_write),
|
||||
path_,
|
||||
});
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
|
||||
Reference in New Issue
Block a user