From c0f19bf6fdc9d3a857ae530db2ab2c5511c7545e Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 Dec 2018 04:21:08 +0300 Subject: [PATCH] Do not drop streaming offset in cancelDownloadFile. GitOrigin-RevId: 9f8699e85ba82ec84c0e85f9510b691f72af0c47 --- td/telegram/Td.cpp | 11 ++++++++++- td/telegram/files/FileGenerateManager.cpp | 2 +- td/telegram/files/FileManager.cpp | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index a01fa000..334edb33 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4859,6 +4859,9 @@ void Td::on_request(uint64 id, const td_api::getFile &request) { } void Td::on_request(uint64 id, const td_api::getFileDownloadedPrefixSize &request) { + if (request.offset_ < 0) { + return send_error_raw(id, 5, "Prefix offset must be non-negative"); + } auto file_view = file_manager_->get_file_view(FileId(request.file_id_, 0)); if (file_view.empty()) { return send_closure(actor_id(this), &Td::send_error, id, Status::Error(10, "Unknown file id")); @@ -5677,6 +5680,9 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) { if (!(1 <= priority && priority <= 32)) { return send_error_raw(id, 5, "Download priority must be in [1;32] range"); } + if (request.offset_ < 0) { + return send_error_raw(id, 5, "Download offset must be non-negative"); + } file_manager_->download(FileId(request.file_id_, 0), download_file_callback_, priority, request.offset_); auto file = file_manager_->get_file_object(FileId(request.file_id_, 0), false); @@ -5688,6 +5694,9 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) { } void Td::on_request(uint64 id, const td_api::setFileDownloadOffset &request) { + if (request.offset_ < 0) { + return send_error_raw(id, 5, "Download offset must be non-negative"); + } file_manager_->download_set_offset(FileId(request.file_id_, 0), request.offset_); auto file = file_manager_->get_file_object(FileId(request.file_id_, 0), false); if (file->id_ == 0) { @@ -5698,7 +5707,7 @@ void Td::on_request(uint64 id, const td_api::setFileDownloadOffset &request) { } void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) { - file_manager_->download(FileId(request.file_id_, 0), nullptr, 0, request.only_if_pending_ ? -1 : 0); + file_manager_->download(FileId(request.file_id_, 0), nullptr, request.only_if_pending_ ? -1 : 0, -1); send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index d2f13fd4..976e3f16 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -87,7 +87,7 @@ class FileDownloadGenerateActor : public FileGenerateActor { -1); } void hangup() override { - send_closure(G()->file_manager(), &FileManager::download, file_id_, nullptr, 0, 0); + send_closure(G()->file_manager(), &FileManager::download, file_id_, nullptr, 0, -1); stop(); } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 3285d10d..ef9ba7fc 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -357,6 +357,7 @@ bool FileView::is_downloading() const { int64 FileView::download_offset() const { return node_->download_offset_; } + int64 FileView::downloaded_prefix(int64 offset) const { switch (node_->local_.type()) { case LocalFileLocation::Type::Empty: @@ -1582,7 +1583,7 @@ void FileManager::download(FileId file_id, std::shared_ptr cal LOG(INFO) << "Change download priority of file " << file_id << " to " << new_priority; if (file_view.is_encrypted_any()) { - // TODO: we need to set it always and just download from the beginning + // TODO: we need to set offset always and just download from the beginning offset = 0; } node->set_download_offset(offset);