From 2e60bfc289c448979a4f240fbe61ab7bdc661585 Mon Sep 17 00:00:00 2001 From: Konstantin Pastbin Date: Mon, 7 Jul 2025 15:27:03 +0700 Subject: [PATCH] [core] Improve downloader logging Signed-off-by: Konstantin Pastbin --- platform/chunks_download_strategy.cpp | 9 ++++++++- platform/http_request.cpp | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/platform/chunks_download_strategy.cpp b/platform/chunks_download_strategy.cpp index bf36d7308..3e895ec1d 100644 --- a/platform/chunks_download_strategy.cpp +++ b/platform/chunks_download_strategy.cpp @@ -43,6 +43,7 @@ void ChunksDownloadStrategy::InitChunks(int64_t fileSize, int64_t chunkSize, Chu m_chunks.reserve(static_cast(fileSize / chunkSize + 2)); for (int64_t i = 0; i < fileSize; i += chunkSize) m_chunks.push_back(ChunkT(i, status)); + // The last AUX chunk is just used to hold end of the range (eof) for the previous chunk. m_chunks.push_back(ChunkT(fileSize, CHUNK_AUX)); } @@ -77,7 +78,7 @@ void ChunksDownloadStrategy::SaveChunks(int64_t fileSize, string const & fName) } catch (FileWriter::Exception const & e) { - LOG(LWARNING, ("Can't save chunks to file", e.Msg())); + LOG(LWARNING, ("Can't save chunks statuses to file", e.Msg())); } } @@ -112,13 +113,19 @@ int64_t ChunksDownloadStrategy::LoadOrInitChunks(string const & fName, int64_t f // Reset status "downloading" to "free". int64_t downloadedSize = 0; + size_t completed = 0; for (size_t i = 0; i < count - 1; ++i) { if (m_chunks[i].m_status != CHUNK_COMPLETE) m_chunks[i].m_status = CHUNK_FREE; else + { downloadedSize += (m_chunks[i + 1].m_pos - m_chunks[i].m_pos); + ++completed; + } } + LOG(LINFO, ("Resumed file: downloaded", downloadedSize / 1024 / 1024, "out of", fileSize / 1024 / 1024, + "MB; completed chunks", completed, "out of", count - 1)); return downloadedSize; } diff --git a/platform/http_request.cpp b/platform/http_request.cpp index 6f103d1de..fe675409a 100644 --- a/platform/http_request.cpp +++ b/platform/http_request.cpp @@ -318,7 +318,10 @@ public: size <= static_cast(fileSize)) openMode = FileWriter::OP_WRITE_EXISTING; else + { + LOG(LWARNING, ("Incomplete file size is bigger than expected, re-downloading.")); m_strategy.InitChunks(fileSize, chunkSize); + } } // Create file and reserve needed size.