From c329826c5d64e7524fecd486df10461fc5e87e72 Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Mon, 29 Jan 2018 20:46:06 +0300 Subject: [PATCH] FileUpload: restart automatically if part_size is too small GitOrigin-RevId: bbfe3f0fca2f888f6bd4d2909935903d7c4e3b33 --- td/telegram/files/FileManager.cpp | 5 +++++ td/telegram/files/FileUploader.cpp | 3 +++ td/telegram/files/PartsManager.cpp | 3 +-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 2a404d66..eb5aabaa 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2190,6 +2190,11 @@ void FileManager::on_error_impl(FileNode *node, FileManager::Query::Type type, b } } + if (status.message() == "FILE_UPLOAD_RESTART") { + run_upload(node, {}); + return; + } + if (!was_active) { return; } diff --git a/td/telegram/files/FileUploader.cpp b/td/telegram/files/FileUploader.cpp index 7c99b58d..26f16fda 100644 --- a/td/telegram/files/FileUploader.cpp +++ b/td/telegram/files/FileUploader.cpp @@ -140,6 +140,9 @@ Result FileUploader::on_update_local_location(const Loca } local_size_ = local_size; + if (expected_size_ < local_size_) { + expected_size_ = local_size_; + } local_is_ready_ = local_is_ready; file_type_ = file_type; diff --git a/td/telegram/files/PartsManager.cpp b/td/telegram/files/PartsManager.cpp index 7122e6b2..eae9ddd1 100644 --- a/td/telegram/files/PartsManager.cpp +++ b/td/telegram/files/PartsManager.cpp @@ -63,8 +63,7 @@ Status PartsManager::init(int64 size, bool is_size_final, size_t part_size, cons if (part_size != 0) { part_size_ = part_size; if (use_part_count_limit_ && (size_ + part_size_ - 1) / part_size_ > MAX_PART_COUNT) { - return Status::Error(PSLICE() << "Should restart load with bigger part_size " << tag("part_size_", part_size_) - << tag("size", size_)); + return Status::Error("FILE_UPLOAD_RESTART"); } } else { // TODO choose part_size_ depending on size