diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index 4f91b577d..9d1e81fe7 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -133,14 +133,18 @@ int64 StorageManager::get_db_size() { int64 size = 0; auto add_path = [&](CSlice path) { TRY_RESULT(info, stat(path)); + + LOG(DEBUG) << "Add database file \"" << path << "\" of size " << info.size_ + << " to database storage size statistics"; size += info.size_; return Status::OK(); }; G()->td_db()->with_db_path([&](CSlice path) { add_path(path).ignore(); }); - add_path(PSLICE() << G()->parameters().database_directory << "log").ignore(); - add_path(PSLICE() << G()->parameters().database_directory << "log.old").ignore(); + for (auto &log_path : log_interface->get_file_paths()) { + add_path(log_path).ignore(); + } return size; } diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index 64f04b058..0d4dc229b 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -369,6 +369,7 @@ static Status check_mtime(std::string &conversion, CSlice original_path) { auto r_stat = stat(original_path); uint64 actual_mtime = r_stat.is_ok() ? r_stat.ok().mtime_nsec_ : 0; if (expected_mtime == actual_mtime) { + LOG(DEBUG) << "File \"" << original_path << "\" modification time " << actual_mtime << " matches"; return Status::OK(); } return Status::Error(PSLICE() << "FILE_GENERATE_LOCATION_INVALID: File \"" << original_path diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index 42c41487f..a0b392c0b 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -22,6 +22,9 @@ Status FileLog::init(string path, int64 rotate_threshold) { set_rotate_threshold(rotate_threshold); return Status::OK(); } + if (path.empty()) { + return Status::Error("Log file path can't be empty"); + } TRY_RESULT(fd, FileFd::open(path, FileFd::Create | FileFd::Write | FileFd::Append)); @@ -31,7 +34,12 @@ Status FileLog::init(string path, int64 rotate_threshold) { fd_.get_native_fd().duplicate(Stderr().get_native_fd()).ignore(); } - path_ = std::move(path); + auto r_path = realpath(path, true); + if (r_path.is_error()) { + path_ = std::move(path); + } else { + path_ = r_path.move_as_ok(); + } size_ = fd_.get_size(); rotate_threshold_ = rotate_threshold; return Status::OK(); @@ -41,6 +49,15 @@ Slice FileLog::get_path() const { return path_; } +vector FileLog::get_file_paths() { + vector result; + if (!path_.empty()) { + result.push_back(path_); + result.push_back(PSTRING() << path_ << ".old"); + } + return result; +} + void FileLog::set_rotate_threshold(int64 rotate_threshold) { rotate_threshold_ = rotate_threshold; } diff --git a/tdutils/td/utils/FileLog.h b/tdutils/td/utils/FileLog.h index 166a071b2..e015d96c3 100644 --- a/tdutils/td/utils/FileLog.h +++ b/tdutils/td/utils/FileLog.h @@ -22,6 +22,8 @@ class FileLog : public LogInterface { Slice get_path() const; + vector get_file_paths() override; + void set_rotate_threshold(int64 rotate_threshold); int64 get_rotate_threshold() const; diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index c9886808f..70d38722f 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -158,6 +158,9 @@ class LogInterface { } virtual void rotate() { } + virtual vector get_file_paths() { + return {}; + } }; class NullLog : public LogInterface { @@ -288,6 +291,12 @@ class TsLog : public LogInterface { log_->rotate(); exit_critical(); } + vector get_file_paths() override { + enter_critical(); + auto result = log_->get_file_paths(); + exit_critical(); + return result; + } private: LogInterface *log_ = nullptr;