From 11c78406c38c5238aff176456622a7412965fc71 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Sep 2023 14:47:17 +0300 Subject: [PATCH] Explicitly check returned errors. --- td/telegram/files/FileDownloader.cpp | 25 +++++++++++++------------ test/tqueue.cpp | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index 71f43fe17..7c40c0a52 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -90,18 +90,19 @@ Result FileDownloader::init() { } } if (need_search_file_ && fd_.empty() && size_ > 0 && encryption_key_.empty() && !remote_.is_web()) { - [&] { - TRY_RESULT(path, search_file(remote_.file_type_, name_, size_)); - TRY_RESULT(fd, FileFd::open(path, FileFd::Read)); - LOG(INFO) << "Check hash of local file " << path; - path_ = std::move(path); - fd_ = std::move(fd); - need_check_ = true; - only_check_ = true; - part_size = 128 * (1 << 10); - bitmask = Bitmask{Bitmask::Ones{}, (size_ + part_size - 1) / part_size}; - return Status::OK(); - }(); + auto r_path = search_file(remote_.file_type_, name_, size_); + if (r_path.is_ok()) { + auto r_fd = FileFd::open(r_path.ok(), FileFd::Read); + if (r_fd.is_ok()) { + path_ = r_path.move_as_ok(); + fd_ = r_fd.move_as_ok(); + need_check_ = true; + only_check_ = true; + part_size = 128 * (1 << 10); + bitmask = Bitmask{Bitmask::Ones{}, (size_ + part_size - 1) / part_size}; + LOG(INFO) << "Check hash of local file " << path_; + } + } } FileInfo res; diff --git a/test/tqueue.cpp b/test/tqueue.cpp index 9c3da0034..9c68daca8 100644 --- a/test/tqueue.cpp +++ b/test/tqueue.cpp @@ -31,7 +31,7 @@ TEST(TQueue, hands) { auto qid = 12; ASSERT_EQ(true, tqueue->get_head(qid).empty()); ASSERT_EQ(true, tqueue->get_tail(qid).empty()); - tqueue->push(qid, "hello", 1, 0, td::TQueue::EventId()); + tqueue->push(qid, "hello", 1, 0, td::TQueue::EventId()).ignore(); auto head = tqueue->get_head(qid); auto tail = tqueue->get_tail(qid); ASSERT_EQ(head.next().ok(), tail);