Author: batosai
Date: 2008-08-11 03:53:41 +0000 (Mon, 11 Aug 2008)
New Revision: 21740

Modified:
   trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
Log:
Keep edition number to the last fetchable one, to avoid giving non-existent 
editions in identity.xml

Modified: trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-08-11 03:43:08 UTC 
(rev 21739)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-08-11 03:53:41 UTC 
(rev 21740)
@@ -39,11 +39,23 @@
        }

        public void fetch(Identity identity) throws FetchException {
+               fetch(identity, false);
+       }
+       
+       public void fetch(Identity identity, boolean nextEdition) throws 
FetchException {

+               FreenetURI uri = identity.getRequestURI().setMetaString(new 
String [] {"identity.xml"}); 
+               if(nextEdition) uri = 
uri.setSuggestedEdition(uri.getSuggestedEdition() + 1);
+               
+               fetch(uri);
+       }
+       
+       private void fetch(FreenetURI uri) throws FetchException {
+               
                FetchContext fetchContext = client.getFetchContext();
                fetchContext.maxSplitfileBlockRetries = -1; // retry forever
                fetchContext.maxNonSplitfileRetries = -1; // retry forever
-               client.fetch(identity.getRequestURI().setMetaString(new String 
[] {"identity.xml"}), -1, this, this, fetchContext);
+               client.fetch(uri, -1, this, this, fetchContext);
        }

        @Override
@@ -105,13 +117,13 @@
                }

                // Update the edition number and commit the changes
-               
identity.setRequestURI(identity.getRequestURI().setSuggestedEdition(state.getURI().getSuggestedEdition()
 + 1));
+               
identity.setRequestURI(identity.getRequestURI().setSuggestedEdition(state.getURI().getSuggestedEdition()));
                db.store(identity);
                db.commit();            

                // Try to fetch next edition
                try {
-                       fetch(identity);
+                       fetch(identity, true);
                } catch (FetchException e) {
                        System.out.println(e.getLocalizedMessage());
                }


Reply via email to