From fae0b8c2f83a460bb02fdac9e0171a40f737edbd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 16:48:46 -0400 Subject: [PATCH] [unpackfs] Re-jig progress reporting - rsync reports its own progress, and reports on files that find -type f doesn't. This meant that the numbers didn't match what was stored in entry.total - The ir-phase adds files to be handled; to-phase happens once ir-phase is over and the remaining files are processed. By adding the to-phase files, percentages over 100% were reported (in part because the number of files doesn't match). - Update expected entries total from rsync output. - Re-jig computation of how done everything is: tally it up in integers, and do only one global progress percentage. --- src/modules/unpackfs/main.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index c250931a0..40cd8c628 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -136,10 +136,10 @@ def file_copy(source, dest, progress_cb): # I guess we're updating every 100 files... if num_files_copied % 100 == 0: - progress_cb(num_files_copied) + progress_cb(num_files_copied, num_files_total_local) process.wait() - progress_cb(num_files_copied) # Push towards 100% + progress_cb(num_files_copied, num_files_total_local) # Push towards 100% # 23 is the return code rsync returns if it cannot write extended # attributes (with -X) because the target file system does not support it, @@ -177,14 +177,19 @@ class UnpackOperation: """ progress = float(0) + done = 0 + total = 0 + complete = 0 for entry in self.entries: if entry.total == 0: continue + total += entry.total + done += entry.copied + if entry.total == entry.copied: + complete += 1 - partialprogress = 0.05 # Having a total !=0 gives 5% - - partialprogress += 0.95 * (entry.copied / float(entry.total)) - progress += partialprogress / len(self.entries) + if done > 0 and total > 0: + progress = 0.05 + (0.90 * done / total) + (0.05 * complete / len(self.entries)) job.setprogress(progress) @@ -263,12 +268,13 @@ class UnpackOperation: :param imgmountdir: :return: """ - def progress_cb(copied): + def progress_cb(copied, total): """ Copies file to given destination target. :param copied: """ entry.copied = copied + entry.total = total self.report_progress() try: