diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index b692c1c1d..820d641f0 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2110,10 +2110,10 @@ tl_object_ptr get_input_media(const MessageContent *co // if we had InputFile, but has failed to use it, then we need to immediately cancel file upload // so the next upload with the same file can succeed CHECK(file_id.is_valid()); - td->file_manager_->upload(file_id, nullptr, 0, 0); + td->file_manager_->cancel_upload(file_id); if (had_input_thumbnail) { CHECK(thumbnail_file_id.is_valid()); - td->file_manager_->upload(thumbnail_file_id, nullptr, 0, 0); + td->file_manager_->cancel_upload(thumbnail_file_id); } } } else { diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a16634052..059c66b67 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6214,7 +6214,7 @@ void MessagesManager::on_load_secret_thumbnail(FileId thumbnail_file_id, BufferS if (m == nullptr) { // message has already been deleted by the user, do not need to send it // cancel file upload of the main file to allow next upload with the same file to succeed - td_->file_manager_->upload(file_id, nullptr, 0, 0); + td_->file_manager_->cancel_upload(file_id); LOG(INFO) << "Message with a media has already been deleted"; return; } @@ -14932,12 +14932,12 @@ void MessagesManager::cancel_upload_message_content_files(const MessageContent * // always cancel file upload, it is a no-op in the worst case if (being_uploaded_files_.erase(file_id) || file_id.is_valid()) { LOG(INFO) << "Cancel upload file " << file_id; - td_->file_manager_->upload(file_id, nullptr, 0, 0); + td_->file_manager_->cancel_upload(file_id); } file_id = get_message_content_thumbnail_file_id(content, td_); if (being_uploaded_thumbnails_.erase(file_id) || file_id.is_valid()) { LOG(INFO) << "Cancel upload thumbnail file " << file_id; - td_->file_manager_->upload(file_id, nullptr, 0, 0); + td_->file_manager_->cancel_upload(file_id); } } @@ -22142,7 +22142,7 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me if (need_finish_upload) { // the file is likely to be already merged with a server file, but if not we need to // cancel file upload of the main file to allow next upload with the same file to succeed - td_->file_manager_->upload(old_file_id, nullptr, 0, 0); + td_->file_manager_->cancel_upload(old_file_id); } if (is_content_changed || need_update) { diff --git a/td/telegram/SecureManager.cpp b/td/telegram/SecureManager.cpp index 1ed9d4d7b..60dcf761a 100644 --- a/td/telegram/SecureManager.cpp +++ b/td/telegram/SecureManager.cpp @@ -527,19 +527,19 @@ void SetSecureValue::tear_down() { return; } for (auto &file_info : files_to_upload_) { - file_manager->upload(file_info.file_id, nullptr, 0, 0); + file_manager->cancel_upload(file_info.file_id); } for (auto &file_info : translations_to_upload_) { - file_manager->upload(file_info.file_id, nullptr, 0, 0); + file_manager->cancel_upload(file_info.file_id); } if (front_side_) { - file_manager->upload(front_side_.value().file_id, nullptr, 0, 0); + file_manager->cancel_upload(front_side_.value().file_id); } if (reverse_side_) { - file_manager->upload(reverse_side_.value().file_id, nullptr, 0, 0); + file_manager->cancel_upload(reverse_side_.value().file_id); } if (selfie_) { - file_manager->upload(selfie_.value().file_id, nullptr, 0, 0); + file_manager->cancel_upload(selfie_.value().file_id); } } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 9d60e5725..6cad68779 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -614,7 +614,7 @@ class UploadStickerFileQuery : public Td::ResultHandler { CHECK(file_id_.is_valid()); if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { // TODO td->stickers_manager_->on_upload_sticker_file_part_missing(file_id_, to_integer(status.message().substr(10))); - return; + // return; } else { if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) { td->file_manager_->delete_partial_remote_location(file_id_); @@ -3310,7 +3310,7 @@ void StickersManager::do_upload_sticker_file(UserId user_id, FileId file_id, if (had_input_file && !FileManager::extract_was_uploaded(input_media)) { // if we had InputFile, but has failed to use it, then we need to immediately cancel file upload // so the next upload with the same file can succeed - td_->file_manager_->upload(file_id, nullptr, 0, 0); + td_->file_manager_->cancel_upload(file_id); } td_->create_handler(std::move(promise)) diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0c8ad4bf3..9ab444d15 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3886,17 +3886,17 @@ class Td::UploadFileCallback : public FileManager::UploadCallback { void on_upload_ok(FileId file_id, tl_object_ptr input_file) override { // cancel file upload of the file to allow next upload with the same file to succeed - send_closure(G()->file_manager(), &FileManager::upload, file_id, nullptr, 0, 0); + send_closure(G()->file_manager(), &FileManager::cancel_upload, file_id); } void on_upload_encrypted_ok(FileId file_id, tl_object_ptr input_file) override { // cancel file upload of the file to allow next upload with the same file to succeed - send_closure(G()->file_manager(), &FileManager::upload, file_id, nullptr, 0, 0); + send_closure(G()->file_manager(), &FileManager::cancel_upload, file_id); } void on_upload_secure_ok(FileId file_id, tl_object_ptr input_file) override { // cancel file upload of the file to allow next upload with the same file to succeed - send_closure(G()->file_manager(), &FileManager::upload, file_id, nullptr, 0, 0); + send_closure(G()->file_manager(), &FileManager::cancel_upload, file_id); } void on_upload_error(FileId file_id, Status error) override { @@ -5700,7 +5700,7 @@ void Td::on_request(uint64 id, td_api::uploadFile &request) { } void Td::on_request(uint64 id, const td_api::cancelUploadFile &request) { - file_manager_->upload(FileId(request.file_id_, 0), nullptr, 0, 0); + file_manager_->cancel_upload(FileId(request.file_id_, 0)); send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 0895a7941..d9c7760d2 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1078,7 +1078,7 @@ static int merge_choose_encryption_key(const FileEncryptionKey &a, const FileEnc return 2; } -void FileManager::cancel_download(FileNodePtr node) { +void FileManager::do_cancel_download(FileNodePtr node) { if (node->download_id_ == 0) { return; } @@ -1089,7 +1089,7 @@ void FileManager::cancel_download(FileNodePtr node) { node->set_download_priority(0); } -void FileManager::cancel_upload(FileNodePtr node) { +void FileManager::do_cancel_upload(FileNodePtr node) { if (node->upload_id_ == 0) { return; } @@ -1099,7 +1099,7 @@ void FileManager::cancel_upload(FileNodePtr node) { node->set_upload_priority(0); } -void FileManager::cancel_generate(FileNodePtr node) { +void FileManager::do_cancel_generate(FileNodePtr node) { if (node->generate_id_ == 0) { return; } @@ -1205,7 +1205,7 @@ Result FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy << ", url_i = " << url_i << ", owner_i = " << owner_i << ", encryption_key_i = " << encryption_key_i << ", main_file_id_i = " << main_file_id_i; if (local_i == other_node_i) { - cancel_download(node); + do_cancel_download(node); node->set_download_offset(other_node->download_offset_); node->set_local_location(other_node->local_, other_node->local_ready_size_, other_node->download_offset_, other_node->local_ready_prefix_size_); @@ -1220,7 +1220,7 @@ Result FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy other_node->download_offset_ = 0; other_node->local_ready_prefix_size_ = 0; - //cancel_generate(node); + //do_cancel_generate(node); //node->set_generate_location(std::move(other_node->generate_)); //node->generate_id_ = other_node->generate_id_; //node->set_generate_priority(other_node->generate_download_priority_, other_node->generate_upload_priority_); @@ -1230,12 +1230,12 @@ Result FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy //other_node->generate_download_priority_ = 0; //other_node->generate_upload_priority_ = 0; } else { - cancel_download(other_node); - //cancel_generate(other_node); + do_cancel_download(other_node); + //do_cancel_generate(other_node); } if (remote_i == other_node_i) { - cancel_upload(node); + do_cancel_upload(node); node->set_remote_location(other_node->remote_, other_node->remote_source_, other_node->remote_ready_size_); node->upload_id_ = other_node->upload_id_; node->upload_was_update_file_reference_ = other_node->upload_was_update_file_reference_; @@ -1246,11 +1246,11 @@ Result FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy other_node->upload_priority_ = 0; other_node->set_upload_pause(FileId()); } else { - cancel_upload(other_node); + do_cancel_upload(other_node); } if (generate_i == other_node_i) { - cancel_generate(node); + do_cancel_generate(node); node->set_generate_location(std::move(other_node->generate_)); node->generate_id_ = other_node->generate_id_; node->set_generate_priority(other_node->generate_download_priority_, other_node->generate_upload_priority_); @@ -1259,7 +1259,7 @@ Result FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy other_node->generate_download_priority_ = 0; other_node->generate_upload_priority_ = 0; } else { - cancel_generate(other_node); + do_cancel_generate(other_node); } if (size_i == other_node_i) { @@ -1621,7 +1621,7 @@ bool FileManager::set_content(FileId file_id, BufferSlice bytes) { return true; } - cancel_download(node); + do_cancel_download(node); auto *file_info = get_file_id_info(file_id); file_info->download_priority_ = FROM_BYTES_PRIORITY; @@ -1772,7 +1772,7 @@ void FileManager::run_download(FileNodePtr node) { if (priority == 0) { if (old_priority != 0) { - cancel_download(node); + do_cancel_download(node); } return; } @@ -1973,7 +1973,7 @@ void FileManager::run_generate(FileNodePtr node) { if (node->generate_priority_ == 0) { if (old_priority != 0) { LOG(INFO) << "Cancel file " << file_id << " generation"; - cancel_generate(node); + do_cancel_generate(node); } return; } @@ -2049,7 +2049,7 @@ void FileManager::run_upload(FileNodePtr node, std::vector bad_parts) { if (priority == 0) { if (old_priority != 0) { LOG(INFO) << "Cancel file " << file_id << " uploading"; - cancel_upload(node); + do_cancel_upload(node); } return; } @@ -2118,6 +2118,10 @@ void FileManager::upload(FileId file_id, std::shared_ptr callbac return resume_upload(file_id, std::vector(), std::move(callback), new_priority, upload_order); } +void FileManager::cancel_upload(FileId file_id) { + return resume_upload(file_id, std::vector(), nullptr, 0, 0); +} + static bool is_document_type(FileType type) { return type == FileType::Document || type == FileType::Sticker || type == FileType::Audio || type == FileType::Animation; @@ -2885,9 +2889,9 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type, } // Stop everything on error - cancel_generate(node); - cancel_download(node); - cancel_upload(node); + do_cancel_generate(node); + do_cancel_download(node); + do_cancel_upload(node); for (auto file_id : vector(node->file_ids_)) { auto *info = get_file_id_info(file_id); diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 7b6f444a4..2ee80ef4b 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -365,6 +365,7 @@ class FileManager : public FileLoadManager::Callback { void upload(FileId file_id, std::shared_ptr callback, int32 new_priority, uint64 upload_order); void resume_upload(FileId file_id, std::vector bad_parts, std::shared_ptr callback, int32 new_priority, uint64 upload_order); + void cancel_upload(FileId file_id); bool delete_partial_remote_location(FileId file_id); void delete_file_reference(FileId file_id, std::string file_reference); void get_content(FileId file_id, Promise promise); @@ -521,9 +522,9 @@ class FileManager : public FileLoadManager::Callback { FileNodePtr get_sync_file_node(FileId file_id); // void release_file_node(FileNodeId id); - void cancel_download(FileNodePtr node); - void cancel_upload(FileNodePtr node); - void cancel_generate(FileNodePtr node); + void do_cancel_download(FileNodePtr node); + void do_cancel_upload(FileNodePtr node); + void do_cancel_generate(FileNodePtr node); void run_upload(FileNodePtr node, std::vector bad_parts); void run_download(FileNodePtr node); void run_generate(FileNodePtr node);