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);
|
||||
|
||||
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}
|
||||
.column("source_path")
|
||||
.where("api_path")
|
||||
.equals("/")
|
||||
.where("source_path")
|
||||
.equals(cfg_path)
|
||||
.and_()
|
||||
.where("directory")
|
||||
.equals(1)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
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(
|
||||
row->get_column("source_path").get_value<std::string>());
|
||||
#if defined(_WIN32)
|
||||
if (utils::string::to_lower(cur_path) !=
|
||||
utils::string::to_lower(cfg_path)) {
|
||||
#else //! defined(_WIN32)
|
||||
if (cur_path != cfg_path) {
|
||||
#endif // defined(_WIN32)
|
||||
throw startup_exception(fmt::print(
|
||||
"source path has changed|cur|{}|cfg|{}", cur_path, cfg.path));
|
||||
}
|
||||
} else {
|
||||
// TODO error handling
|
||||
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
|
||||
.column_value("api_path", "/")
|
||||
.column_value("data", "")
|
||||
.column_value("directory", 1)
|
||||
.column_value("source_path", cfg.path)
|
||||
.go();
|
||||
source_path = cfg.path;
|
||||
}
|
||||
|
||||
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}
|
||||
.column_value("api_path", "/")
|
||||
.column_value("data", "")
|
||||
.column_value("directory", 1)
|
||||
.column_value("source_path", source_path)
|
||||
.column_value("source_path", cfg_path)
|
||||
.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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user