mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[core] Improve downloader logging
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
fdbb41e0fd
commit
2e60bfc289
@@ -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;
|
||||
}
|
||||
|
||||
@@ -318,8 +318,11 @@ 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.
|
||||
unique_ptr<FileWriter> writer(new FileWriter(filePath + DOWNLOADING_FILE_EXTENSION, openMode));
|
||||
|
||||
Reference in New Issue
Block a user