From f2c37cae260c4050fb64d224aa827c7ed4e7fb3d Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Sun, 18 Aug 2013 20:09:14 -0700 Subject: [PATCH 1/2] Fix division-by-zero bug --- src/bitrot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitrot.py b/src/bitrot.py index 97fe219..4275b99 100644 --- a/src/bitrot.py +++ b/src/bitrot.py @@ -112,7 +112,7 @@ def run(verbosity=1, test=False): new_mtime = int(st.st_mtime) current_size += st.st_size if verbosity: - size_fmt = '\r{:>6.1%}'.format(current_size/total_size) + size_fmt = '\r{:>6.1%}'.format(current_size/total_size if total_size > 0 else 0) if size_fmt != last_reported_size: sys.stdout.write(size_fmt) sys.stdout.flush() From 37104d7b78352c2b3e6c954056b81853fbf20aa2 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 23 Aug 2013 14:04:09 -0700 Subject: [PATCH 2/2] Clean up division by zero fix --- src/bitrot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitrot.py b/src/bitrot.py index 4275b99..cd449db 100644 --- a/src/bitrot.py +++ b/src/bitrot.py @@ -112,7 +112,7 @@ def run(verbosity=1, test=False): new_mtime = int(st.st_mtime) current_size += st.st_size if verbosity: - size_fmt = '\r{:>6.1%}'.format(current_size/total_size if total_size > 0 else 0) + size_fmt = '\r{:>6.1%}'.format(current_size/(total_size or 1)) if size_fmt != last_reported_size: sys.stdout.write(size_fmt) sys.stdout.flush()