Browse code

Fix potential divide by zero errors

Daniel Harris authored on 2014/07/25 04:06:00
Showing 1 changed files
... ...
@@ -917,9 +917,7 @@ def cmd_sync_remote2remote(args):
917 917
         failed_copy_files[key]['target_uri'] = destination_base + key
918 918
     seq = _upload(failed_copy_files, seq, failed_copy_count)
919 919
 
920
-    total_elapsed = time.time() - timestamp_start
921
-    if total_elapsed == 0.0:
922
-        total_elapsed = 1.0
920
+    total_elapsed = max(1.0, time.time() - timestamp_start)
923 921
     outstr = "Done. Copied %d files in %0.1f seconds, %0.2f files/s" % (seq, total_elapsed, seq/total_elapsed)
924 922
     if seq > 0:
925 923
         output(outstr)
... ...
@@ -1148,7 +1146,7 @@ def cmd_sync_remote2local(args):
1148 1148
     _set_local_filename(failed_copy_list, destination_base)
1149 1149
     seq, total_size = _download(failed_copy_list, seq, len(failed_copy_list) + remote_count + update_count, total_size, dir_cache)
1150 1150
 
1151
-    total_elapsed = time.time() - timestamp_start
1151
+    total_elapsed = max(1.0, time.time() - timestamp_start)
1152 1152
     speed_fmt = formatSize(total_size/total_elapsed, human_readable = True, floating_point = True)
1153 1153
 
1154 1154
     # Only print out the result if any work has been done or
... ...
@@ -1399,7 +1397,7 @@ def cmd_sync_local2remote(args):
1399 1399
 
1400 1400
         if cfg.delete_removed and cfg.delete_after and remote_list:
1401 1401
             subcmd_batch_del(remote_list = remote_list)
1402
-        total_elapsed = time.time() - timestamp_start
1402
+        total_elapsed = max(1.0, time.time() - timestamp_start)
1403 1403
         total_speed = total_elapsed and total_size/total_elapsed or 0.0
1404 1404
         speed_fmt = formatSize(total_speed, human_readable = True, floating_point = True)
1405 1405