Don't add not downloaded files to recent downloads.
This commit is contained in:
parent
1607707ef8
commit
02c5fcd476
@ -415,6 +415,10 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
}
|
||||
|
||||
static void remove_from_db(const FileInfo &file_info) {
|
||||
if (!is_database_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
G()->td_db()->get_binlog_pmc()->erase(pmc_key(file_info));
|
||||
}
|
||||
|
||||
@ -448,10 +452,6 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_db.completed_at > 0) {
|
||||
// TODO file must not be added if it isn't fully downloaded
|
||||
}
|
||||
|
||||
auto file_info = make_unique<FileInfo>();
|
||||
file_info->download_id = in_db.download_id;
|
||||
file_info->file_id = in_db.file_id;
|
||||
@ -530,13 +530,20 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
CHECK(file_info != nullptr);
|
||||
auto download_id = file_info->download_id;
|
||||
file_info->internal_file_id = callback_->dup_file_id(file_info->file_id);
|
||||
auto file_view = callback_->get_file_view(file_info->file_id);
|
||||
auto file_view = callback_->get_sync_file_view(file_info->file_id);
|
||||
CHECK(!file_view.empty());
|
||||
file_info->size = file_view.size();
|
||||
file_info->expected_size = file_view.expected_size();
|
||||
file_info->downloaded_size = file_view.local_total_size();
|
||||
file_info->is_counted = !is_completed(*file_info);
|
||||
|
||||
if (file_info->completed_at > 0 && (file_info->size == 0 || file_info->downloaded_size != file_info->size)) {
|
||||
LOG(INFO) << "Skip adding file " << file_info->file_id << " to recently downloaded files, because local size is "
|
||||
<< file_info->downloaded_size << " instead of expected " << file_info->size;
|
||||
remove_from_db(*file_info);
|
||||
return;
|
||||
}
|
||||
|
||||
by_internal_file_id_[file_info->internal_file_id] = download_id;
|
||||
by_file_id_[file_info->file_id] = download_id;
|
||||
hints_.add(download_id, search_text.empty() ? string(" ") : search_text);
|
||||
|
@ -52,6 +52,7 @@ class DownloadManager : public Actor {
|
||||
virtual FileId dup_file_id(FileId file_id) = 0;
|
||||
|
||||
virtual FileView get_file_view(FileId file_id) = 0;
|
||||
virtual FileView get_sync_file_view(FileId file_id) = 0;
|
||||
virtual td_api::object_ptr<td_api::fileDownload> get_file_download_object(FileId file_id,
|
||||
FileSourceId file_source_id,
|
||||
int32 add_date, int32 complete_date,
|
||||
|
@ -51,6 +51,10 @@ FileView DownloadManagerCallback::get_file_view(FileId file_id) {
|
||||
return td_->file_manager_->get_file_view(file_id);
|
||||
}
|
||||
|
||||
FileView DownloadManagerCallback::get_sync_file_view(FileId file_id) {
|
||||
return td_->file_manager_->get_sync_file_view(file_id);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::fileDownload> DownloadManagerCallback::get_file_download_object(
|
||||
FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date, bool is_paused) {
|
||||
return td_api::make_object<td_api::fileDownload>(td_->file_manager_->get_file_view(file_id).file_id().get(),
|
||||
@ -84,7 +88,6 @@ std::shared_ptr<FileManager::DownloadCallback> DownloadManagerCallback::make_dow
|
||||
auto file_view = td->file_manager_->get_file_view(file_id);
|
||||
send_closure(download_manager_, &DownloadManager::update_file_download_state, file_id,
|
||||
file_view.local_total_size(), file_view.size(), file_view.expected_size(), is_paused);
|
||||
// TODO: handle deleted state?
|
||||
}
|
||||
};
|
||||
return std::make_shared<Impl>(td, std::move(download_manager));
|
||||
|
@ -38,6 +38,8 @@ class DownloadManagerCallback final : public DownloadManager::Callback {
|
||||
|
||||
FileView get_file_view(FileId file_id) final;
|
||||
|
||||
FileView get_sync_file_view(FileId file_id) final;
|
||||
|
||||
td_api::object_ptr<td_api::fileDownload> get_file_download_object(FileId file_id, FileSourceId file_source_id,
|
||||
int32 add_date, int32 complete_date,
|
||||
bool is_paused);
|
||||
|
@ -420,7 +420,7 @@ class CliClient final : public Actor {
|
||||
LOG(INFO) << "Logged in";
|
||||
break;
|
||||
case td_api::authorizationStateClosed::ID:
|
||||
LOG(WARNING) << "TD closed";
|
||||
LOG(WARNING) << "Td closed";
|
||||
td_client_.reset();
|
||||
if (!close_flag_) {
|
||||
create_td("ClientActor3");
|
||||
@ -997,7 +997,7 @@ class CliClient final : public Actor {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(WARNING) << "Creating new TD " << name << " with generation " << generation_ + 1;
|
||||
LOG(WARNING) << "Creating new Td " << name << " with generation " << generation_ + 1;
|
||||
class TdCallbackImpl final : public TdCallback {
|
||||
public:
|
||||
TdCallbackImpl(CliClient *client, uint64 generation) : client_(client), generation_(generation) {
|
||||
|
Loading…
Reference in New Issue
Block a user