Author: toad
Date: 2006-03-24 18:38:39 +0000 (Fri, 24 Mar 2006)
New Revision: 8301

Modified:
   trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
   trunk/freenet/src/freenet/node/Version.java
Log:
564: Fix division by zero, try to catch the cause...

Modified: trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java 
2006-03-24 18:11:38 UTC (rev 8300)
+++ trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java 
2006-03-24 18:38:39 UTC (rev 8301)
@@ -1,5 +1,7 @@
 package freenet.client.events;

+import freenet.support.Logger;
+
 public class SplitfileProgressEvent implements ClientEvent {

        public static int code = 0x07;
@@ -8,7 +10,7 @@
        public final int fetchedBlocks;
        public final int failedBlocks;
        public final int fatallyFailedBlocks;
-       public final int minSuccessfulBlocks;
+       public int minSuccessfulBlocks;
        public final boolean finalizedTotal;

        public SplitfileProgressEvent(int totalBlocks, int fetchedBlocks, int 
failedBlocks, 
@@ -22,8 +24,30 @@
        }

        public String getDescription() {
-               return "Completed 
"+(100*(fetchedBlocks)/minSuccessfulBlocks)+"% 
"+fetchedBlocks+"/"+minSuccessfulBlocks+" (failed "+failedBlocks+", fatally 
"+fatallyFailedBlocks+", total "+totalBlocks+")" +
-                       (finalizedTotal ? " (finalized total)" : "");
+               StringBuffer sb = new StringBuffer();
+               sb.append("Completed ");
+               if(minSuccessfulBlocks == 0 && fetchedBlocks == 0)
+                       minSuccessfulBlocks = 1;
+               if(minSuccessfulBlocks == 0) {
+                       Logger.error(this, "minSuccessfulBlocks=0, 
fetchedBlocks="+fetchedBlocks+", totalBlocks="+totalBlocks+
+                                       ", failedBlocks="+failedBlocks+", 
fatallyFailedBlocks="+fatallyFailedBlocks+", finalizedTotal="+finalizedTotal, 
new Exception("debug"));
+               } else {
+                       sb.append((100*(fetchedBlocks)/minSuccessfulBlocks));
+                       sb.append('%');
+               }
+               sb.append(' ');
+               sb.append(fetchedBlocks);
+               sb.append('/');
+               sb.append(minSuccessfulBlocks);
+               sb.append(" (failed ");
+               sb.append(failedBlocks);
+               sb.append(", fatally ");
+               sb.append(fatallyFailedBlocks);
+               sb.append(", total ");
+               sb.append(totalBlocks);
+               sb.append(") ");
+               sb.append(finalizedTotal ? " (finalized total)" : "");
+               return sb.toString();
        }

        public int getCode() {

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-03-24 18:11:38 UTC (rev 
8300)
+++ trunk/freenet/src/freenet/node/Version.java 2006-03-24 18:38:39 UTC (rev 
8301)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 563;
+       private static final int buildNumber = 564;

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 507;


Reply via email to