diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 1ff7686d..3c60237b 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -283,20 +283,20 @@ Status TdDb::init_sqlite(int32 scheduler_id, const TdParameters ¶meters, DbK CHECK(!parameters.use_message_db || parameters.use_chat_info_db); CHECK(!parameters.use_chat_info_db || parameters.use_file_db); - const string sql_db_name = get_sqlite_path(parameters); + const string sql_database_path = get_sqlite_path(parameters); bool use_sqlite = parameters.use_file_db; bool use_file_db = parameters.use_file_db; bool use_dialog_db = parameters.use_message_db; bool use_message_db = parameters.use_message_db; if (!use_sqlite) { - unlink(sql_db_name).ignore(); + unlink(sql_database_path).ignore(); return Status::OK(); } - sqlite_path_ = sql_db_name; + sqlite_path_ = sql_database_path; TRY_STATUS(SqliteDb::change_key(sqlite_path_, key, old_key)); - sql_connection_ = std::make_shared(sql_db_name, key); + sql_connection_ = std::make_shared(sql_database_path, key); auto &db = sql_connection_->get(); TRY_STATUS(init_db(db)); diff --git a/td/telegram/TdDb.h b/td/telegram/TdDb.h index 3d18e4b9..879328ee 100644 --- a/td/telegram/TdDb.h +++ b/td/telegram/TdDb.h @@ -126,4 +126,5 @@ class TdDb { void do_close(Promise<> on_finished, bool destroy_flag); }; + } // namespace td diff --git a/tddb/td/db/SqliteConnectionSafe.cpp b/tddb/td/db/SqliteConnectionSafe.cpp index f178ad0f..547bf20c 100644 --- a/tddb/td/db/SqliteConnectionSafe.cpp +++ b/tddb/td/db/SqliteConnectionSafe.cpp @@ -9,14 +9,20 @@ #include "td/utils/common.h" #include "td/utils/format.h" #include "td/utils/logging.h" +#include "td/utils/port/Stat.h" namespace td { -SqliteConnectionSafe::SqliteConnectionSafe(string name, DbKey key) - : name_(std::move(name)), lsls_connection_([name = name_, key = std::move(key)] { - auto r_db = SqliteDb::open_with_key(name, key); +SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key) + : path_(std::move(path)), lsls_connection_([path = path_, key = std::move(key)] { + auto r_db = SqliteDb::open_with_key(path, key); if (r_db.is_error()) { - LOG(FATAL) << "Can't open database " << name << ": " << r_db.error(); + auto r_stat = stat(path); + if (r_stat.is_error()) { + LOG(FATAL) << "Can't open database " << path << " (" << r_stat.error() << "): " << r_db.error(); + } else { + LOG(FATAL) << "Can't open database " << path << " of size " << r_stat.ok().size_ << ": " << r_db.error(); + } } auto db = r_db.move_as_ok(); db.exec("PRAGMA synchronous=NORMAL").ensure(); @@ -32,14 +38,14 @@ SqliteDb &SqliteConnectionSafe::get() { } void SqliteConnectionSafe::close() { - LOG(INFO) << "Close SQLite database " << tag("path", name_); + LOG(INFO) << "Close SQLite database " << tag("path", path_); lsls_connection_.clear_values(); } void SqliteConnectionSafe::close_and_destroy() { close(); - LOG(INFO) << "Destroy SQLite database " << tag("path", name_); - SqliteDb::destroy(name_).ignore(); + LOG(INFO) << "Destroy SQLite database " << tag("path", path_); + SqliteDb::destroy(path_).ignore(); } } // namespace td diff --git a/tddb/td/db/SqliteConnectionSafe.h b/tddb/td/db/SqliteConnectionSafe.h index f0a78104..b53b3691 100644 --- a/tddb/td/db/SqliteConnectionSafe.h +++ b/tddb/td/db/SqliteConnectionSafe.h @@ -18,7 +18,7 @@ namespace td { class SqliteConnectionSafe { public: SqliteConnectionSafe() = default; - explicit SqliteConnectionSafe(string name, DbKey key = DbKey::empty()); + explicit SqliteConnectionSafe(string path, DbKey key = DbKey::empty()); SqliteDb &get(); @@ -27,7 +27,7 @@ class SqliteConnectionSafe { void close_and_destroy(); private: - string name_; + string path_; LazySchedulerLocalStorage lsls_connection_; };