Add FileManager::get_missing_file_parts.

This commit is contained in:
levlam 2023-07-05 10:55:16 +03:00
parent e3e1eda011
commit ad193a389c
10 changed files with 65 additions and 44 deletions

View File

@ -225,8 +225,9 @@ class UploadBackgroundQuery final : public Td::ResultHandler {
void on_error(Status status) final { void on_error(Status status) final {
CHECK(file_id_.is_valid()); CHECK(file_id_.is_valid());
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
// TODO td_->background_manager_->on_upload_background_file_part_missing(file_id_, to_integer<int32>(status.message().substr(10))); if (!bad_parts.empty()) {
// TODO td_->background_manager_->on_upload_background_file_parts_missing(file_id_, std::move(bad_parts));
// return; // return;
} else { } else {
if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) { if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) {

View File

@ -458,8 +458,9 @@ void CallActor::on_save_log_query_result(FileId file_id, Promise<Unit> promise,
auto res = fetch_result<telegram_api::phone_saveCallLog>(std::move(r_net_query)); auto res = fetch_result<telegram_api::phone_saveCallLog>(std::move(r_net_query));
if (res.is_error()) { if (res.is_error()) {
auto error = res.move_as_error(); auto error = res.move_as_error();
if (begins_with(error.message(), "FILE_PART_") && ends_with(error.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(error);
// TODO on_upload_log_file_part_missing(file_id, to_integer<int32>(error.message().substr(10))); if (!bad_parts.empty()) {
// TODO on_upload_log_file_parts_missing(file_id, std::move(bad_parts));
// return; // return;
} }
return promise.set_error(std::move(error)); return promise.set_error(std::move(error));

View File

@ -980,8 +980,9 @@ class InitHistoryImportQuery final : public Td::ResultHandler {
if (FileReferenceManager::is_file_reference_error(status)) { if (FileReferenceManager::is_file_reference_error(status)) {
LOG(ERROR) << "Receive file reference error " << status; LOG(ERROR) << "Receive file reference error " << status;
} }
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
// TODO support FILE_PART_*_MISSING if (!bad_parts.empty()) {
// TODO reupload the file
} }
td_->file_manager_->delete_partial_remote_location(file_id_); td_->file_manager_->delete_partial_remote_location(file_id_);
@ -1033,8 +1034,9 @@ class UploadImportedMediaQuery final : public Td::ResultHandler {
if (FileReferenceManager::is_file_reference_error(status)) { if (FileReferenceManager::is_file_reference_error(status)) {
LOG(ERROR) << "Receive file reference error " << status; LOG(ERROR) << "Receive file reference error " << status;
} }
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
// TODO support FILE_PART_*_MISSING if (!bad_parts.empty()) {
// TODO reupload the file
} }
td_->file_manager_->delete_partial_remote_location(file_id_); td_->file_manager_->delete_partial_remote_location(file_id_);
@ -3534,9 +3536,9 @@ class SendMediaQuery final : public Td::ResultHandler {
} }
CHECK(file_id_.is_valid()); CHECK(file_id_.is_valid());
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
td_->messages_manager_->on_send_message_file_part_missing(random_id_, if (!bad_parts.empty()) {
to_integer<int32>(status.message().substr(10))); td_->messages_manager_->on_send_message_file_parts_missing(random_id_, std::move(bad_parts));
return; return;
} else { } else {
if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) { if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) {
@ -3623,9 +3625,10 @@ class UploadMediaQuery final : public Td::ResultHandler {
} }
CHECK(file_id_.is_valid()); CHECK(file_id_.is_valid());
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
td_->messages_manager_->on_upload_message_media_file_part_missing( if (!bad_parts.empty()) {
dialog_id_, message_id_, to_integer<int32>(status.message().substr(10))); td_->messages_manager_->on_upload_message_media_file_parts_missing(dialog_id_, message_id_,
std::move(bad_parts));
return; return;
} else { } else {
if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) { if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) {
@ -13852,8 +13855,9 @@ void MessagesManager::on_send_secret_message_error(int64 random_id, Status error
// do not send error, message will be re-sent after restart // do not send error, message will be re-sent after restart
return; return;
} }
if (begins_with(error.message(), "FILE_PART_") && ends_with(error.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(error);
on_send_message_file_part_missing(random_id, to_integer<int32>(error.message().substr(10))); if (!bad_parts.empty()) {
on_send_message_file_parts_missing(random_id, std::move(bad_parts));
return; return;
} }
@ -25623,8 +25627,8 @@ void MessagesManager::on_upload_message_media_success(DialogId dialog_id, Messag
m->message_id, std::move(result)); m->message_id, std::move(result));
} }
void MessagesManager::on_upload_message_media_file_part_missing(DialogId dialog_id, MessageId message_id, void MessagesManager::on_upload_message_media_file_parts_missing(DialogId dialog_id, MessageId message_id,
int bad_part) { vector<int> &&bad_parts) {
Dialog *d = get_dialog(dialog_id); Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr); CHECK(d != nullptr);
@ -25644,7 +25648,7 @@ void MessagesManager::on_upload_message_media_file_part_missing(DialogId dialog_
CHECK(dialog_id.get_type() != DialogType::SecretChat); CHECK(dialog_id.get_type() != DialogType::SecretChat);
do_send_message(dialog_id, m, {bad_part}); do_send_message(dialog_id, m, std::move(bad_parts));
} }
void MessagesManager::on_upload_message_media_fail(DialogId dialog_id, MessageId message_id, Status error) { void MessagesManager::on_upload_message_media_fail(DialogId dialog_id, MessageId message_id, Status error) {
@ -26742,9 +26746,9 @@ void MessagesManager::on_message_media_edited(DialogId dialog_id, MessageId mess
td_->file_manager_->delete_partial_remote_location(thumbnail_file_id); td_->file_manager_->delete_partial_remote_location(thumbnail_file_id);
} }
CHECK(file_id.is_valid()); CHECK(file_id.is_valid());
auto error_message = result.error().message(); auto bad_parts = FileManager::get_missing_file_parts(result.error());
if (begins_with(error_message, "FILE_PART_") && ends_with(error_message, "_MISSING")) { if (!bad_parts.empty()) {
do_send_message(dialog_id, m, {to_integer<int32>(error_message.substr(10))}); do_send_message(dialog_id, m, std::move(bad_parts));
return; return;
} }
@ -31049,13 +31053,12 @@ FullMessageId MessagesManager::on_send_message_success(int64 random_id, MessageI
return {dialog_id, new_message_id}; return {dialog_id, new_message_id};
} }
void MessagesManager::on_send_message_file_part_missing(int64 random_id, int bad_part) { void MessagesManager::on_send_message_file_parts_missing(int64 random_id, vector<int> &&bad_parts) {
auto it = being_sent_messages_.find(random_id); auto it = being_sent_messages_.find(random_id);
if (it == being_sent_messages_.end()) { if (it == being_sent_messages_.end()) {
// we can't receive fail more than once // we can't receive fail more than once
// but message can be successfully sent before // but message can be successfully sent before
LOG(WARNING) << "Receive FILE_PART_" << bad_part LOG(INFO) << "Receive error for successfully sent message with random_id = " << random_id;
<< "_MISSING about successfully sent message with random_id = " << random_id;
return; return;
} }
@ -31091,7 +31094,7 @@ void MessagesManager::on_send_message_file_part_missing(int64 random_id, int bad
get_log_event_storer(log_event)); get_log_event_storer(log_event));
} }
do_send_message(dialog_id, m, {bad_part}); do_send_message(dialog_id, m, std::move(bad_parts));
} }
void MessagesManager::on_send_message_file_reference_error(int64 random_id) { void MessagesManager::on_send_message_file_reference_error(int64 random_id) {

View File

@ -944,7 +944,7 @@ class MessagesManager final : public Actor {
FullMessageId on_send_message_success(int64 random_id, MessageId new_message_id, int32 date, int32 ttl_period, FullMessageId on_send_message_success(int64 random_id, MessageId new_message_id, int32 date, int32 ttl_period,
FileId new_file_id, const char *source); FileId new_file_id, const char *source);
void on_send_message_file_part_missing(int64 random_id, int bad_part); void on_send_message_file_parts_missing(int64 random_id, vector<int> &&bad_parts);
void on_send_message_file_reference_error(int64 random_id); void on_send_message_file_reference_error(int64 random_id);
@ -955,7 +955,7 @@ class MessagesManager final : public Actor {
void on_upload_message_media_success(DialogId dialog_id, MessageId message_id, void on_upload_message_media_success(DialogId dialog_id, MessageId message_id,
tl_object_ptr<telegram_api::MessageMedia> &&media); tl_object_ptr<telegram_api::MessageMedia> &&media);
void on_upload_message_media_file_part_missing(DialogId dialog_id, MessageId message_id, int bad_part); void on_upload_message_media_file_parts_missing(DialogId dialog_id, MessageId message_id, vector<int> &&bad_parts);
void on_upload_message_media_fail(DialogId dialog_id, MessageId message_id, Status error); void on_upload_message_media_fail(DialogId dialog_id, MessageId message_id, Status error);

View File

@ -83,8 +83,9 @@ class UploadRingtoneQuery final : public Td::ResultHandler {
if (FileReferenceManager::is_file_reference_error(status)) { if (FileReferenceManager::is_file_reference_error(status)) {
LOG(ERROR) << "Receive file reference error " << status; LOG(ERROR) << "Receive file reference error " << status;
} }
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
// TODO support FILE_PART_*_MISSING if (!bad_parts.empty()) {
// TODO reupload the file
} }
td_->file_manager_->delete_partial_remote_location(file_id_); td_->file_manager_->delete_partial_remote_location(file_id_);

View File

@ -1057,8 +1057,9 @@ class UploadStickerFileQuery final : public Td::ResultHandler {
void on_error(Status status) final { void on_error(Status status) final {
if (was_uploaded_) { if (was_uploaded_) {
CHECK(file_id_.is_valid()); CHECK(file_id_.is_valid());
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
// TODO td_->stickers_manager_->on_upload_sticker_file_part_missing(file_id_, to_integer<int32>(status.message().substr(10))); if (!bad_parts.empty()) {
// TODO td_->stickers_manager_->on_upload_sticker_file_parts_missing(file_id_, std::move(bad_parts));
// return; // return;
} else { } else {
if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) { if (status.code() != 429 && status.code() < 500 && !G()->close_flag()) {
@ -8340,8 +8341,6 @@ void StickersManager::on_upload_sticker_file_error(FileId file_id, Status status
being_uploaded_files_.erase(it); being_uploaded_files_.erase(it);
// TODO FILE_PART_X_MISSING support
promise.set_error(Status::Error(status.code() > 0 ? status.code() : 500, promise.set_error(Status::Error(status.code() > 0 ? status.code() : 500,
status.message())); // TODO CHECK that status has always a code status.message())); // TODO CHECK that status has always a code
} }

View File

@ -584,9 +584,9 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler {
return; return;
} }
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
td_->story_manager_->on_send_story_file_part_missing(std::move(pending_story_), if (!bad_parts.empty()) {
to_integer<int32>(status.message().substr(10))); td_->story_manager_->on_send_story_file_parts_missing(std::move(pending_story_), std::move(bad_parts));
return; return;
} else { } else {
td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), std::move(status)); td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), std::move(status));
@ -655,9 +655,9 @@ class StoryManager::EditStoryQuery final : public Td::ResultHandler {
return td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), Status::OK()); return td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), Status::OK());
} }
if (begins_with(status.message(), "FILE_PART_") && ends_with(status.message(), "_MISSING")) { auto bad_parts = FileManager::get_missing_file_parts(status);
td_->story_manager_->on_send_story_file_part_missing(std::move(pending_story_), if (!bad_parts.empty()) {
to_integer<int32>(status.message().substr(10))); td_->story_manager_->on_send_story_file_parts_missing(std::move(pending_story_), std::move(bad_parts));
return; return;
} }
td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), std::move(status)); td_->story_manager_->delete_pending_story(file_id_, std::move(pending_story_), std::move(status));
@ -2748,8 +2748,8 @@ void StoryManager::on_upload_story_error(FileId file_id, Status status) {
delete_pending_story(file_id, std::move(pending_story), std::move(status)); delete_pending_story(file_id, std::move(pending_story), std::move(status));
} }
void StoryManager::on_send_story_file_part_missing(unique_ptr<PendingStory> &&pending_story, int bad_part) { void StoryManager::on_send_story_file_parts_missing(unique_ptr<PendingStory> &&pending_story, vector<int> &&bad_parts) {
do_send_story(std::move(pending_story), {bad_part}); do_send_story(std::move(pending_story), std::move(bad_parts));
} }
class StoryManager::EditStoryLogEvent { class StoryManager::EditStoryLogEvent {

View File

@ -141,7 +141,7 @@ class StoryManager final : public Actor {
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, int32 active_period, bool is_pinned, td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, int32 active_period, bool is_pinned,
bool protect_content, Promise<td_api::object_ptr<td_api::story>> &&promise); bool protect_content, Promise<td_api::object_ptr<td_api::story>> &&promise);
void on_send_story_file_part_missing(unique_ptr<PendingStory> &&pending_story, int bad_part); void on_send_story_file_parts_missing(unique_ptr<PendingStory> &&pending_story, vector<int> &&bad_parts);
void edit_story(StoryId story_id, td_api::object_ptr<td_api::InputStoryContent> &&input_story_content, void edit_story(StoryId story_id, td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
td_api::object_ptr<td_api::formattedText> &&input_caption, Promise<Unit> &&promise); td_api::object_ptr<td_api::formattedText> &&input_caption, Promise<Unit> &&promise);

View File

@ -933,6 +933,20 @@ bool FileManager::is_remotely_generated_file(Slice conversion) {
return begins_with(conversion, "#map#") || begins_with(conversion, "#audio_t#"); return begins_with(conversion, "#map#") || begins_with(conversion, "#audio_t#");
} }
vector<int> FileManager::get_missing_file_parts(const Status &error) {
vector<int> result;
auto error_message = error.message();
if (begins_with(error_message, "FILE_PART_") && ends_with(error_message, "_MISSING")) {
auto r_file_part = to_integer_safe<int>(error_message.substr(10, error_message.size() - 18));
if (r_file_part.is_error()) {
LOG(ERROR) << "Receive error " << error;
} else {
result.push_back(r_file_part.ok());
}
}
return result;
}
void FileManager::check_local_location(FileId file_id, bool skip_file_size_checks) { void FileManager::check_local_location(FileId file_id, bool skip_file_size_checks) {
auto node = get_sync_file_node(file_id); auto node = get_sync_file_node(file_id);
if (node) { if (node) {

View File

@ -421,6 +421,8 @@ class FileManager final : public FileLoadManager::Callback {
static bool is_remotely_generated_file(Slice conversion); static bool is_remotely_generated_file(Slice conversion);
static vector<int> get_missing_file_parts(const Status &error);
void init_actor(); void init_actor();
FileId dup_file_id(FileId file_id, const char *source); FileId dup_file_id(FileId file_id, const char *source);
@ -461,7 +463,7 @@ class FileManager final : public FileLoadManager::Callback {
void download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset, void download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset,
int64 limit, Promise<td_api::object_ptr<td_api::file>> promise); int64 limit, Promise<td_api::object_ptr<td_api::file>> promise);
void upload(FileId file_id, std::shared_ptr<UploadCallback> callback, int32 new_priority, uint64 upload_order); void upload(FileId file_id, std::shared_ptr<UploadCallback> callback, int32 new_priority, uint64 upload_order);
void resume_upload(FileId file_id, std::vector<int> bad_parts, std::shared_ptr<UploadCallback> callback, void resume_upload(FileId file_id, vector<int> bad_parts, std::shared_ptr<UploadCallback> callback,
int32 new_priority, uint64 upload_order, bool force = false, bool prefer_small = false); int32 new_priority, uint64 upload_order, bool force = false, bool prefer_small = false);
void cancel_upload(FileId file_id); void cancel_upload(FileId file_id);
bool delete_partial_remote_location(FileId file_id); bool delete_partial_remote_location(FileId file_id);