From 028300650d936240c6d3a4da4fb30da62dd44692 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 21 Jun 2014 15:01:09 -0500 Subject: [PATCH] write.c: Send "write streams" progress at least every 5 MB This is helpful when writing large archives, especially when the library user uses the ability to abort the operation. --- src/write.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/write.c b/src/write.c index 2baba967..56eb5dd4 100644 --- a/src/write.c +++ b/src/write.c @@ -312,10 +312,28 @@ do_write_streams_progress(struct write_streams_progress_data *progress_data, if (progress_data->next_progress == progress->write_streams.total_bytes) { progress_data->next_progress = ~(uint64_t)0; } else { + /* Handle rate-limiting of messages */ + + /* Send new message as soon as another 1/128 of the + * total has been written. (Arbitrary number.) */ progress_data->next_progress = - min(progress->write_streams.total_bytes, - progress->write_streams.completed_bytes + - progress->write_streams.total_bytes / 100); + progress->write_streams.completed_bytes + + progress->write_streams.total_bytes / 128; + + /* ... Unless that would be more than 5000000 bytes, in + * which case send the next after the next 5000000 + * bytes. (Another arbitrary number.) */ + if (progress->write_streams.completed_bytes + 5000000 < + progress_data->next_progress) + progress_data->next_progress = + progress->write_streams.completed_bytes + 5000000; + + /* ... But always send a message as soon as we're + * completely done. */ + if (progress->write_streams.total_bytes < + progress_data->next_progress) + progress_data->next_progress = + progress->write_streams.total_bytes; } } return 0; -- 2.43.0