]> wimlib.net Git - wimlib/commitdiff
write.c: Send "write streams" progress at least every 5 MB
authorEric Biggers <ebiggers3@gmail.com>
Sat, 21 Jun 2014 20:01:09 +0000 (15:01 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 21 Jun 2014 20:09:41 +0000 (15:09 -0500)
This is helpful when writing large archives, especially when the library
user uses the ability to abort the operation.

src/write.c

index 2baba967390bd4cdda51c079c3cb8f66f409449b..56eb5dd46e5dc8db1ee2a9148c57da427dae0c8a 100644 (file)
@@ -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;