From 9302481d937dd275f047b4e716f2cf6960816dc5 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 28 Dec 2018 01:48:21 +0300 Subject: [PATCH] Set download offset for encrypted files. GitOrigin-RevId: 505d464839bc33e6a969b24dcaddab34863c5f7c --- td/telegram/files/FileLoaderUtils.cpp | 1 + td/telegram/files/FileManager.cpp | 15 ++++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/td/telegram/files/FileLoaderUtils.cpp b/td/telegram/files/FileLoaderUtils.cpp index 87cd30a7..61ebed99 100644 --- a/td/telegram/files/FileLoaderUtils.cpp +++ b/td/telegram/files/FileLoaderUtils.cpp @@ -76,6 +76,7 @@ bool for_suggested_file_name(CSlice name, bool use_pmc, bool use_random, F &&cal if (r_path.is_error()) { return true; } + LOG(DEBUG) << "Trying " << r_path.ok(); return callback(r_path.move_as_ok()); }; auto cleaned_name = clean_filename(name); diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index e96340f5..12fef9cc 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1607,10 +1607,6 @@ 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 offset always and just download from the beginning - offset = 0; - } node->set_download_offset(offset); auto *file_info = get_file_id_info(file_id); CHECK(new_priority == 0 || callback); @@ -1630,9 +1626,6 @@ void FileManager::download_set_offset(FileId file_id, int64 offset) { LOG(INFO) << "File " << file_id << " not found"; return; } - if (FileView(file_node).is_encrypted_any()) { - offset = 0; - } file_node->set_download_offset(offset); run_generate(file_node); run_download(file_node); @@ -1674,8 +1667,8 @@ void FileManager::run_download(FileNodePtr node) { CHECK(node->download_id_ != 0); send_closure(file_load_manager_, &FileLoadManager::update_priority, node->download_id_, priority); if (need_update_offset) { - send_closure(file_load_manager_, &FileLoadManager::update_download_offset, node->download_id_, - node->download_offset_); + auto download_offset = file_view.is_encrypted_any() ? 0 : node->download_offset_; + send_closure(file_load_manager_, &FileLoadManager::update_download_offset, node->download_id_, download_offset); } return; } @@ -1688,9 +1681,9 @@ void FileManager::run_download(FileNodePtr node) { node->is_download_started_ = false; LOG(DEBUG) << "Run download of file " << file_id << " of size " << node->size_ << " from " << node->remote_.full() << " with suggested name " << node->suggested_name() << " and encyption key " << node->encryption_key_; + auto download_offset = file_view.is_encrypted_any() ? 0 : node->download_offset_; send_closure(file_load_manager_, &FileLoadManager::download, id, node->remote_.full(), node->local_, node->size_, - node->suggested_name(), node->encryption_key_, node->can_search_locally_, node->download_offset_, - priority); + node->suggested_name(), node->encryption_key_, node->can_search_locally_, download_offset, priority); } void FileManager::resume_upload(FileId file_id, std::vector bad_parts, std::shared_ptr callback,