fix encrypt provider start
This commit is contained in:
parent
4aebc2502d
commit
9d00a87851
@ -1042,46 +1042,41 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
|
|||||||
sql_create_tables);
|
sql_create_tables);
|
||||||
|
|
||||||
auto cfg = config_.get_encrypt_config();
|
auto cfg = config_.get_encrypt_config();
|
||||||
|
auto cfg_path = utils::path::absolute(cfg.path);
|
||||||
|
|
||||||
std::string source_path;
|
|
||||||
auto result = utils::db::sqlite::db_select{*db_, file_table}
|
auto result = utils::db::sqlite::db_select{*db_, file_table}
|
||||||
.column("source_path")
|
.column("source_path")
|
||||||
.where("api_path")
|
.where("source_path")
|
||||||
.equals("/")
|
.equals(cfg_path)
|
||||||
.and_()
|
.and_()
|
||||||
.where("directory")
|
.where("directory")
|
||||||
.equals(1)
|
.equals(1)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_result::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
source_path = row->get_column("source_path").get_value<std::string>();
|
auto cur_path = utils::path::absolute(
|
||||||
} else {
|
row->get_column("source_path").get_value<std::string>());
|
||||||
// TODO error handling
|
#if defined(_WIN32)
|
||||||
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
|
if (utils::string::to_lower(cur_path) !=
|
||||||
.column_value("api_path", "/")
|
utils::string::to_lower(cfg_path)) {
|
||||||
.column_value("data", "")
|
#else //! defined(_WIN32)
|
||||||
.column_value("directory", 1)
|
if (cur_path != cfg_path) {
|
||||||
.column_value("source_path", cfg.path)
|
#endif // defined(_WIN32)
|
||||||
.go();
|
throw startup_exception(fmt::print(
|
||||||
source_path = cfg.path;
|
"source path has changed|cur|{}|cfg|{}", cur_path, cfg.path));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
result = utils::db::sqlite::db_select{*db_, file_table}
|
|
||||||
.column("api_path")
|
|
||||||
.where("source_path")
|
|
||||||
.equals(source_path)
|
|
||||||
.and_()
|
|
||||||
.where("directory")
|
|
||||||
.equals(1)
|
|
||||||
.go();
|
|
||||||
if (not result.has_row()) {
|
|
||||||
// TODO error handling
|
|
||||||
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
|
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
|
||||||
.column_value("api_path", "/")
|
.column_value("api_path", "/")
|
||||||
.column_value("data", "")
|
.column_value("data", "")
|
||||||
.column_value("directory", 1)
|
.column_value("directory", 1)
|
||||||
.column_value("source_path", source_path)
|
.column_value("source_path", cfg_path)
|
||||||
.go();
|
.go();
|
||||||
|
if (not ins_res.ok()) {
|
||||||
|
throw startup_exception(fmt::print("failed to create root|{}|{}",
|
||||||
|
ins_res.get_error(),
|
||||||
|
ins_res.get_error_str()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
polling::instance().set_callback({
|
polling::instance().set_callback({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user