From: Eric Biggers Date: Sat, 21 Jun 2014 20:01:09 +0000 (-0500) Subject: write.c: Send "write streams" progress at least every 5 MB X-Git-Tag: v1.7.1~91 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=028300650d936240c6d3a4da4fb30da62dd44692;ds=sidebyside 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. --- 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;