Make call to should_restart_part safe.

This commit is contained in:
levlam 2023-09-07 17:31:08 +03:00
parent edc528457f
commit 00258ccb4c
3 changed files with 6 additions and 6 deletions

View File

@ -149,7 +149,7 @@ void FileDownloader::on_error(Status status) {
callback_->on_error(std::move(status));
}
Result<bool> FileDownloader::should_restart_part(Part part, NetQueryPtr &net_query) {
Result<bool> FileDownloader::should_restart_part(Part part, const NetQueryPtr &net_query) {
// Check if we should use CDN or reupload file to CDN
if (net_query->is_error()) {
@ -166,7 +166,7 @@ Result<bool> FileDownloader::should_restart_part(Part part, NetQueryPtr &net_que
switch (narrow_cast<QueryType>(UniqueId::extract_key(net_query->id()))) {
case QueryType::Default: {
if (net_query->ok_tl_constructor() == telegram_api::upload_fileCdnRedirect::ID) {
TRY_RESULT(file_base, fetch_result<telegram_api::upload_getFile>(std::move(net_query)));
TRY_RESULT(file_base, fetch_result<telegram_api::upload_getFile>(net_query->ok()));
CHECK(file_base->get_id() == telegram_api::upload_fileCdnRedirect::ID);
auto file = move_tl_object_as<telegram_api::upload_fileCdnRedirect>(file_base);
LOG(DEBUG) << "Downloading of part " << part.id << " was redirected to " << oneline(to_string(file));
@ -193,14 +193,14 @@ Result<bool> FileDownloader::should_restart_part(Part part, NetQueryPtr &net_que
return false;
}
case QueryType::ReuploadCDN: {
TRY_RESULT(file_hashes, fetch_result<telegram_api::upload_reuploadCdnFile>(std::move(net_query)));
TRY_RESULT(file_hashes, fetch_result<telegram_api::upload_reuploadCdnFile>(net_query->ok()));
add_hash_info(file_hashes);
LOG(DEBUG) << "Part " << part.id << " was reuplaoded to CDN";
return true;
}
case QueryType::CDN: {
if (net_query->ok_tl_constructor() == telegram_api::upload_cdnFileReuploadNeeded::ID) {
TRY_RESULT(file_base, fetch_result<telegram_api::upload_getCdnFile>(std::move(net_query)));
TRY_RESULT(file_base, fetch_result<telegram_api::upload_getCdnFile>(net_query->ok()));
CHECK(file_base->get_id() == telegram_api::upload_cdnFileReuploadNeeded::ID);
auto file = move_tl_object_as<telegram_api::upload_cdnFileReuploadNeeded>(file_base);
LOG(DEBUG) << "Part " << part.id << " must be reuplaoded to " << oneline(to_string(file));

View File

@ -83,7 +83,7 @@ class FileDownloader final : public FileLoader {
Result<FileInfo> init() final TD_WARN_UNUSED_RESULT;
Status on_ok(int64 size) final TD_WARN_UNUSED_RESULT;
void on_error(Status status) final;
Result<bool> should_restart_part(Part part, NetQueryPtr &net_query) final TD_WARN_UNUSED_RESULT;
Result<bool> should_restart_part(Part part, const NetQueryPtr &net_query) final TD_WARN_UNUSED_RESULT;
Result<std::pair<NetQueryPtr, bool>> start_part(Part part, int32 part_count,
int64 streaming_offset) final TD_WARN_UNUSED_RESULT;
Result<size_t> process_part(Part part, NetQueryPtr net_query) final TD_WARN_UNUSED_RESULT;

View File

@ -88,7 +88,7 @@ class FileLoader : public FileLoaderActor {
int64 file_size) TD_WARN_UNUSED_RESULT {
return Status::Error("Unsupported");
}
virtual Result<bool> should_restart_part(Part part, NetQueryPtr &net_query) TD_WARN_UNUSED_RESULT {
virtual Result<bool> should_restart_part(Part part, const NetQueryPtr &net_query) TD_WARN_UNUSED_RESULT {
return false;
}