From: Patryck Rouleau Date: Mon, 31 Mar 2014 01:21:31 +0000 (-0400) Subject: index-cmd: prevent a division by zero while computing paths_per_second. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=42aed30bc1b18334aaf14630cdcf3d3e8712d903;p=packages%2Fb%2Fbup.git index-cmd: prevent a division by zero while computing paths_per_second. Signed-off-by: Patryck Rouleau Reviewed-by: Rob Browning --- diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index 92a2791..b7fe8f1 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -88,10 +88,12 @@ def update_index(top, excluded_paths, exclude_rxs): if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)): sys.stdout.write('%s\n' % path) sys.stdout.flush() - paths_per_sec = total / (time.time() - index_start) + elapsed = time.time() - index_start + paths_per_sec = total / elapsed if elapsed else 0 qprogress('Indexing: %d (%d paths/s)\r' % (total, paths_per_sec)) elif not (total % 128): - paths_per_sec = total / (time.time() - index_start) + elapsed = time.time() - index_start + paths_per_sec = total / elapsed if elapsed else 0 qprogress('Indexing: %d (%d paths/s)\r' % (total, paths_per_sec)) total += 1 while rig.cur and rig.cur.name > path: # deleted paths @@ -149,7 +151,8 @@ def update_index(top, excluded_paths, exclude_rxs): if not stat.S_ISDIR(pst.st_mode) and pst.st_nlink > 1: hlinks.add_path(path, pst.st_dev, pst.st_ino) - paths_per_sec = total / (time.time() - index_start) + elapsed = time.time() - index_start + paths_per_sec = total / elapsed if elapsed else 0 progress('Indexing: %d, done (%d paths/s).\n' % (total, paths_per_sec)) hlinks.prepare_save()