Skip to content

Commit c180d51

Browse files
committed
common : clean up map after successful download
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
1 parent 3f49035 commit c180d51

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

common/download.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,16 @@ static void print_progress(size_t current, size_t total) {
490490

491491
static std::mutex mutex;
492492
static std::map<std::thread::id, int> lines;
493+
static int max_line = 0;
493494

494495
std::lock_guard<std::mutex> lock(mutex);
495496
std::thread::id id = std::this_thread::get_id();
496497

497498
if (lines.find(id) == lines.end()) {
498-
lines[id] = lines.size();
499+
lines[id] = max_line++;
499500
std::cout << "\n";
500501
}
501-
int lines_up = lines.size() - lines[id];
502+
int lines_up = max_line - lines[id];
502503

503504
size_t width = 50;
504505
size_t pct = (100 * current) / total;
@@ -519,6 +520,13 @@ static void print_progress(size_t current, size_t total) {
519520
<< "\033[u";
520521

521522
std::cout.flush();
523+
524+
if (current == total) {
525+
lines.erase(id);
526+
if (lines.empty()) {
527+
max_line = 0;
528+
}
529+
}
522530
}
523531

524532
static bool common_pull_file(httplib::Client & cli,

0 commit comments

Comments
 (0)