Compare commits
4 Commits
854caffea8
...
9aafb62961
Author | SHA1 | Date | |
---|---|---|---|
9aafb62961 | |||
891040479b | |||
55bcf082ec | |||
67053645e1 |
@ -1,15 +1,15 @@
|
||||
set(BINUTILS_VERSION 2.41)
|
||||
set(BOOST_MAJOR_VERSION 1)
|
||||
set(BOOST_MINOR_VERSION 85)
|
||||
set(BOOST_PATCH_VERSION 0)
|
||||
set(BOOST2_MAJOR_VERSION 1)
|
||||
set(BOOST2_MINOR_VERSION 76)
|
||||
set(BOOST2_PATCH_VERSION 0)
|
||||
set(BOOST_MAJOR_VERSION 1)
|
||||
set(BOOST_MINOR_VERSION 85)
|
||||
set(BOOST_PATCH_VERSION 0)
|
||||
set(CPP_HTTPLIB_VERSION 0.16.3)
|
||||
set(CURL_VERSION 8.9.1)
|
||||
set(CURL2_VERSION 8_9_1)
|
||||
set(EXPAT_VERSION 2.6.2)
|
||||
set(CURL_VERSION 8.9.1)
|
||||
set(EXPAT2_VERSION 2_6_2)
|
||||
set(EXPAT_VERSION 2.6.2)
|
||||
set(GCC_VERSION 14.2.0)
|
||||
set(GTEST_VERSION 1.15.2)
|
||||
set(ICU_VERSION 75-1)
|
||||
@ -21,7 +21,7 @@ set(OPENSSL_VERSION 3.3.1)
|
||||
set(PKG_CONFIG_VERSION 0.29.2)
|
||||
set(PUGIXML_VERSION 1.14)
|
||||
set(SPDLOG_VERSION 1.14.1)
|
||||
set(SQLITE_VERSION 3460100)
|
||||
set(SQLITE2_VERSION 3.46.1)
|
||||
set(SQLITE_VERSION 3460100)
|
||||
set(STDUUID_VERSION 1.2.3)
|
||||
set(ZLIB_VERSION 1.3.1)
|
||||
|
@ -458,7 +458,7 @@ private:
|
||||
i_provider &provider_;
|
||||
|
||||
private:
|
||||
utils::db::sqlite::db3_t db_{nullptr};
|
||||
utils::db::sqlite::db3_t db_;
|
||||
std::uint64_t next_handle_{0U};
|
||||
mutable std::recursive_mutex open_file_mtx_;
|
||||
std::unordered_map<std::string, std::shared_ptr<i_closeable_open_file>>
|
||||
|
@ -115,7 +115,10 @@ file_manager::file_manager(app_config &config, i_provider &provider)
|
||||
throw startup_exception("failed to open db|" + db_path + '|' +
|
||||
std::to_string(res) + '|' + sqlite3_errstr(res));
|
||||
}
|
||||
db_.reset(db3);
|
||||
db_ = utils::db::sqlite::db3_t{
|
||||
db3,
|
||||
utils::db::sqlite::sqlite3_deleter(),
|
||||
};
|
||||
|
||||
for (auto &&create_item : sql_create_tables) {
|
||||
std::string err;
|
||||
|
@ -1058,7 +1058,10 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
|
||||
'|' + sqlite3_errstr(res));
|
||||
return false;
|
||||
}
|
||||
db_.reset(db3);
|
||||
db_ = utils::db::sqlite::db3_t{
|
||||
db3,
|
||||
utils::db::sqlite::sqlite3_deleter(),
|
||||
};
|
||||
|
||||
for (auto &&create : sql_create_tables) {
|
||||
std::string err;
|
||||
|
@ -48,7 +48,11 @@ meta_db::meta_db(const app_config &cfg) {
|
||||
'|' + sqlite3_errstr(res));
|
||||
return;
|
||||
}
|
||||
db_.reset(db3);
|
||||
|
||||
db_ = utils::db::sqlite::db3_t{
|
||||
db3,
|
||||
utils::db::sqlite::sqlite3_deleter(),
|
||||
};
|
||||
|
||||
const auto *create = "CREATE TABLE IF NOT EXISTS "
|
||||
"meta "
|
||||
|
@ -174,7 +174,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
struct netbios_ns_deleter final {
|
||||
void operator()(netbios_ns *ns) {
|
||||
void operator()(netbios_ns *ns) const {
|
||||
if (ns != nullptr) {
|
||||
netbios_ns_destroy(ns);
|
||||
}
|
||||
@ -190,7 +190,7 @@ inline const auto smb_session_deleter = [](smb_session *session) {
|
||||
using smb_session_t = std::shared_ptr<smb_session>;
|
||||
|
||||
struct smb_stat_deleter final {
|
||||
void operator()(smb_stat st) {
|
||||
void operator()(smb_stat st) const {
|
||||
if (st != nullptr) {
|
||||
smb_stat_destroy(st);
|
||||
}
|
||||
@ -199,7 +199,7 @@ struct smb_stat_deleter final {
|
||||
using smb_stat_t = std::unique_ptr<smb_file, smb_stat_deleter>;
|
||||
|
||||
struct smb_stat_list_deleter final {
|
||||
void operator()(smb_file *list) {
|
||||
void operator()(smb_file *list) const {
|
||||
if (list != nullptr) {
|
||||
smb_stat_list_destroy(list);
|
||||
}
|
||||
@ -241,7 +241,7 @@ using smb_stat_list_t = std::unique_ptr<smb_file, smb_stat_list_deleter>;
|
||||
}
|
||||
|
||||
struct vlc_deleter final {
|
||||
void operator()(libvlc_instance_t *inst) {
|
||||
void operator()(libvlc_instance_t *inst) const {
|
||||
if (inst != nullptr) {
|
||||
libvlc_release(inst);
|
||||
}
|
||||
@ -250,7 +250,7 @@ struct vlc_deleter final {
|
||||
using vlc_t = std::unique_ptr<libvlc_instance_t, vlc_deleter>;
|
||||
|
||||
struct vlc_media_deleter final {
|
||||
void operator()(libvlc_media_t *media) {
|
||||
void operator()(libvlc_media_t *media) const {
|
||||
if (media != nullptr) {
|
||||
libvlc_media_release(media);
|
||||
}
|
||||
@ -259,7 +259,7 @@ struct vlc_media_deleter final {
|
||||
using vlc_media_t = std::unique_ptr<libvlc_media_t, vlc_media_deleter>;
|
||||
|
||||
struct vlc_media_list_deleter final {
|
||||
void operator()(libvlc_media_list_t *media_list) {
|
||||
void operator()(libvlc_media_list_t *media_list) const {
|
||||
if (media_list != nullptr) {
|
||||
libvlc_media_list_release(media_list);
|
||||
}
|
||||
@ -269,7 +269,7 @@ using vlc_media_list_t =
|
||||
std::unique_ptr<libvlc_media_list_t, vlc_media_list_deleter>;
|
||||
|
||||
struct vlc_string_deleter final {
|
||||
void operator()(char *str) {
|
||||
void operator()(char *str) const {
|
||||
if (str != nullptr) {
|
||||
libvlc_free(str);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace repertory::utils::db::sqlite {
|
||||
using db_types_t = std::variant<std::int64_t, std::string>;
|
||||
|
||||
struct sqlite3_deleter {
|
||||
void operator()(sqlite3 *db3) {
|
||||
void operator()(sqlite3 *db3) const {
|
||||
if (db3 != nullptr) {
|
||||
sqlite3_close_v2(db3);
|
||||
}
|
||||
@ -37,7 +37,7 @@ struct sqlite3_deleter {
|
||||
using db3_t = std::unique_ptr<sqlite3, sqlite3_deleter>;
|
||||
|
||||
struct sqlite3_statement_deleter {
|
||||
void operator()(sqlite3_stmt *stmt) {
|
||||
void operator()(sqlite3_stmt *stmt) const {
|
||||
if (stmt != nullptr) {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
@ -59,10 +59,11 @@ struct db_comp_data_t final {
|
||||
struct db_context_t {
|
||||
db_context_t(sqlite3 &db3_, std::string table_name_)
|
||||
: db3(db3_), table_name(std::move(table_name_)) {}
|
||||
|
||||
sqlite3 &db3;
|
||||
std::string table_name;
|
||||
|
||||
db3_stmt_t stmt{nullptr};
|
||||
db3_stmt_t stmt;
|
||||
};
|
||||
|
||||
class db_column final {
|
||||
@ -178,6 +179,8 @@ template <typename ctx_t> struct db_result final {
|
||||
}
|
||||
}
|
||||
|
||||
~db_result() { context_->clear(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<ctx_t> context_;
|
||||
mutable std::int32_t res_;
|
||||
|
@ -37,6 +37,11 @@ public:
|
||||
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
void clear() {
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
|
||||
bool or_replace{false};
|
||||
std::map<std::string, db_types_t> values{};
|
||||
|
||||
void clear() { values.clear(); }
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
@ -33,14 +33,24 @@ public:
|
||||
struct context final : db_context_t {
|
||||
context(sqlite3 &db3_, std::string table_name_)
|
||||
: db_context_t(db3_, table_name_) {}
|
||||
|
||||
using w_t = db_where_with_limit_t<context, db_select>;
|
||||
|
||||
std::vector<std::string> columns{};
|
||||
std::map<std::string, std::string> count_columns{};
|
||||
std::vector<std::string> columns;
|
||||
std::map<std::string, std::string> count_columns;
|
||||
std::optional<std::int32_t> limit;
|
||||
std::optional<std::pair<std::string, bool>> order_by;
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
void clear() {
|
||||
columns.clear();
|
||||
count_columns.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
@ -35,11 +35,19 @@ public:
|
||||
: db_context_t(db3_, table_name_) {}
|
||||
using w_t = db_where_with_limit_t<context, db_update>;
|
||||
|
||||
std::map<std::string, db_types_t> column_values{};
|
||||
std::map<std::string, db_types_t> column_values;
|
||||
std::optional<std::int32_t> limit;
|
||||
std::optional<std::pair<std::string, bool>> order_by;
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
void clear() {
|
||||
column_values.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
@ -39,20 +39,19 @@ auto db_delete::dump() const -> std::string {
|
||||
}
|
||||
|
||||
auto db_delete::go() const -> db_result<context> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
sqlite3_stmt *stmt_ptr{nullptr};
|
||||
auto query_str = dump();
|
||||
auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,
|
||||
&stmt_ptr, nullptr);
|
||||
context_->stmt = db3_stmt_t{
|
||||
stmt_ptr,
|
||||
sqlite3_statement_deleter(),
|
||||
};
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
context_->stmt.reset(stmt_ptr);
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||
res = std::visit(
|
||||
|
@ -60,20 +60,19 @@ auto db_insert::dump() const -> std::string {
|
||||
}
|
||||
|
||||
auto db_insert::go() const -> db_result<context> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
sqlite3_stmt *stmt_ptr{nullptr};
|
||||
auto query_str = dump();
|
||||
auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,
|
||||
&stmt_ptr, nullptr);
|
||||
context_->stmt = db3_stmt_t{
|
||||
stmt_ptr,
|
||||
sqlite3_statement_deleter(),
|
||||
};
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
context_->stmt.reset(stmt_ptr);
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->values.size()); idx++) {
|
||||
res = std::visit(
|
||||
|
@ -85,20 +85,19 @@ auto db_select::dump() const -> std::string {
|
||||
}
|
||||
|
||||
auto db_select::go() const -> db_result<context> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
sqlite3_stmt *stmt_ptr{nullptr};
|
||||
auto query_str = dump();
|
||||
auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,
|
||||
&stmt_ptr, nullptr);
|
||||
context_->stmt = db3_stmt_t{
|
||||
stmt_ptr,
|
||||
sqlite3_statement_deleter(),
|
||||
};
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
context_->stmt.reset(stmt_ptr);
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||
res = std::visit(
|
||||
|
@ -64,18 +64,18 @@ auto db_update::dump() const -> std::string {
|
||||
}
|
||||
|
||||
auto db_update::go() const -> db_result<context> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
sqlite3_stmt *stmt_ptr{nullptr};
|
||||
auto query_str = dump();
|
||||
auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,
|
||||
&stmt_ptr, nullptr);
|
||||
context_->stmt = db3_stmt_t{
|
||||
stmt_ptr,
|
||||
sqlite3_statement_deleter(),
|
||||
};
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
context_->stmt.reset(stmt_ptr);
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->column_values.size()); idx++) {
|
||||
|
@ -119,9 +119,11 @@ void file::open() {
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
file_.reset(_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO));
|
||||
file_ = file_t(_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO),
|
||||
file_deleter());
|
||||
#else // !defined(_WIN32)
|
||||
file_.reset(fopen(path_.c_str(), read_only_ ? "rb" : "rb+"));
|
||||
file_ =
|
||||
file_t(fopen(path_.c_str(), read_only_ ? "rb" : "rb+"), file_deleter());
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,14 @@ auto smb_directory::open(std::string_view host, std::string_view user,
|
||||
};
|
||||
|
||||
try {
|
||||
smb_session_t session{smb_session_new(), smb_session_deleter};
|
||||
netbios_ns_t ns{netbios_ns_new()};
|
||||
smb_session_t session{
|
||||
smb_session_new(),
|
||||
smb_session_deleter(),
|
||||
};
|
||||
netbios_ns_t ns{
|
||||
netbios_ns_new(),
|
||||
netbios_ns_deleter(),
|
||||
};
|
||||
|
||||
sockaddr_in addr{};
|
||||
|
||||
@ -137,7 +143,9 @@ auto smb_directory::count(bool recursive) const -> std::uint64_t {
|
||||
}
|
||||
|
||||
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()),
|
||||
smb_stat_list_deleter(),
|
||||
};
|
||||
auto count = smb_stat_list_count(list.get());
|
||||
|
||||
if (not recursive) {
|
||||
@ -247,8 +255,11 @@ auto smb_directory::exists() const -> bool {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
}
|
||||
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_,
|
||||
smb_create_relative_path(path_).c_str())};
|
||||
smb_stat_t st{
|
||||
smb_fstat(session_.get(), tid_,
|
||||
smb_create_relative_path(path_).c_str()),
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
return false;
|
||||
}
|
||||
@ -275,7 +286,10 @@ auto smb_directory::get_directory(std::string_view path) const
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_and_validate_relative_path(path_, path);
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_, rel_path.c_str())};
|
||||
smb_stat_t st{
|
||||
smb_fstat(session_.get(), tid_, rel_path.c_str()),
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
}
|
||||
@ -313,7 +327,9 @@ auto smb_directory::get_directories() const -> std::vector<fs_directory_t> {
|
||||
}
|
||||
|
||||
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()),
|
||||
smb_stat_list_deleter(),
|
||||
};
|
||||
if (not list) {
|
||||
throw std::runtime_error("failed to get directory list|" + path_);
|
||||
}
|
||||
@ -365,7 +381,10 @@ auto smb_directory::get_file(std::string_view path) const -> fs_file_t {
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_and_validate_relative_path(path_, path);
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_, rel_path.c_str())};
|
||||
smb_stat_t st{
|
||||
smb_fstat(session_.get(), tid_, rel_path.c_str()),
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat file|" + rel_path);
|
||||
}
|
||||
@ -398,7 +417,9 @@ auto smb_directory::get_files() const -> std::vector<fs_file_t> {
|
||||
}
|
||||
|
||||
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()),
|
||||
smb_stat_list_deleter(),
|
||||
};
|
||||
if (not list) {
|
||||
throw std::runtime_error("failed to get file list|" + path_);
|
||||
}
|
||||
@ -440,7 +461,9 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
|
||||
}
|
||||
|
||||
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()),
|
||||
smb_stat_list_deleter(),
|
||||
};
|
||||
if (not list) {
|
||||
throw std::runtime_error("failed to get item list|" + path_);
|
||||
}
|
||||
|
@ -70,8 +70,11 @@ auto smb_file::exists() const -> bool {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
}
|
||||
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_,
|
||||
smb_create_relative_path(path_).c_str())};
|
||||
smb_stat_t st{
|
||||
smb_fstat(session_.get(), tid_,
|
||||
smb_create_relative_path(path_).c_str()),
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
return false;
|
||||
}
|
||||
@ -113,7 +116,10 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path);
|
||||
smb_stat_t st{smb_fstat(session, tid, rel_path.c_str())};
|
||||
smb_stat_t st{
|
||||
smb_fstat(session, tid, rel_path.c_str()),
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
}
|
||||
@ -368,7 +374,10 @@ auto smb_file::size() const -> std::optional<std::uint64_t> {
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path_);
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_, rel_path.c_str())};
|
||||
smb_stat_t st{
|
||||
smb_fstat(session_.get(), tid_, rel_path.c_str()),
|
||||
smb_stat_deleter(),
|
||||
};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
}
|
||||
|
@ -34,7 +34,10 @@ public:
|
||||
auto res = sqlite3_open(":memory:", &db3_ptr);
|
||||
ASSERT_EQ(SQLITE_OK, res);
|
||||
ASSERT_TRUE(db3_ptr != nullptr);
|
||||
db3.reset(db3_ptr);
|
||||
db3 = utils::db::sqlite::db3_t{
|
||||
db3_ptr,
|
||||
utils::db::sqlite::sqlite3_deleter(),
|
||||
};
|
||||
}
|
||||
|
||||
utils::db::sqlite::db3_stmt_t db3_stmt;
|
||||
@ -47,8 +50,11 @@ public:
|
||||
sqlite3_stmt *stmt_ptr{nullptr};
|
||||
auto res =
|
||||
sqlite3_prepare_v2(db3.get(), sql.c_str(), -1, &stmt_ptr, nullptr);
|
||||
db3_stmt = utils::db::sqlite::db3_stmt_t{
|
||||
stmt_ptr,
|
||||
utils::db::sqlite::sqlite3_statement_deleter(),
|
||||
};
|
||||
ASSERT_EQ(SQLITE_OK, res);
|
||||
db3_stmt.reset(stmt_ptr);
|
||||
}
|
||||
|
||||
auto res = sqlite3_step(db3_stmt.get());
|
||||
|
Reference in New Issue
Block a user