From 672e27564ed8bb1de3dcad2eddc29878ed07f6b2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 6 Oct 2020 13:29:15 +0200 Subject: [PATCH] [unpackfs] Also report progress every half-second, if possible This still won't help if there's one really huge file that takes several seconds to write, but if there's a bunch of files together that is less than a file_chunk_count but take more than a half- second to write, update anyway --- src/modules/unpackfs/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 8bbe63861..a573cf6e7 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -163,6 +163,8 @@ def file_copy(source, entry, progress_cb): :param progress_cb: A callback function for progress reporting. Takes a number and a total-number. """ + import time + dest = entry.destination # Environment used for executing rsync properly @@ -191,12 +193,13 @@ def file_copy(source, entry, progress_cb): args, env=at_env, stdout=subprocess.PIPE, close_fds=ON_POSIX ) - # last_num_files_copied trails num_files_copied, and whenever at least 100 more + # last_num_files_copied trails num_files_copied, and whenever at least 107 more # files (file_count_chunk) have been copied, progress is reported and - # last_num_files_copied is updated. Pick a chunk size that isn't "tidy" + # last_num_files_copied is updated. The chunk size isn't "tidy" # so that all the digits of the progress-reported number change. # last_num_files_copied = 0 + last_timestamp_reported = time.time() file_count_chunk = 107 for line in iter(process.stdout.readline, b''): @@ -222,9 +225,10 @@ def file_copy(source, entry, progress_cb): # adjusting the offset so that progressbar can be continuesly drawn num_files_copied = num_files_total_local - num_files_remaining - # Update about once every 1% of this entry - if num_files_copied - last_num_files_copied >= file_count_chunk: + now = time.time() + if (num_files_copied - last_num_files_copied >= file_count_chunk) or (now - last_timestamp_reported > 0.5): last_num_files_copied = num_files_copied + last_timestamp_reported = now progress_cb(num_files_copied, num_files_total_local) process.wait()