[core] Improve downloader logging

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-07-07 15:27:03 +07:00
committed by Konstantin Pastbin
parent fdbb41e0fd
commit 2e60bfc289
2 changed files with 11 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ void ChunksDownloadStrategy::InitChunks(int64_t fileSize, int64_t chunkSize, Chu
m_chunks.reserve(static_cast<size_t>(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;
}

View File

@@ -318,7 +318,10 @@ public:
size <= static_cast<uint64_t>(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.