Author: jflesch
Date: 2007-01-26 20:48:26 +0000 (Fri, 26 Jan 2007)
New Revision: 11622

Modified:
   trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
Log:
Fix index insertion

Modified: trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2007-01-26 20:14:14 UTC 
(rev 11621)
+++ trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2007-01-26 20:48:26 UTC 
(rev 11622)
@@ -164,14 +164,14 @@


        protected static String changeRev(final String revStr, final int rev, 
final int offset) {
-               if (rev >= 0)
+               if (offset == 0)
                        return Integer.toString(rev);

                return Integer.toString(Integer.parseInt(revStr) + offset);
        }

        /**
-        * @param rev if < 0, then rev is changed according to the given offset
+        * @param offset if == 0, then rev is changed according to the given 
offset
         */
        public static String changeSSKRevision(String key, final int rev, final 
int offset) {

@@ -208,6 +208,32 @@
        }


+       public static String changeUSKRevision(String key, int rev, int offset) 
{
+               if (key == null)
+                       return null;
+
+               final String[] split = key.split("/");
+
+               key = "";
+
+               for (int i = 0 ; i < split.length ; i++) {
+                       switch(i) {
+                       case(0):
+                               key = key + split[i];
+                               break;
+                       case(2):
+                               key = key + "/" + 
FreenetURIHelper.changeRev(split[2], rev, offset);
+                               break;
+                       default:
+                               key = key + "/" + split[i];
+                       }
+               }
+
+               return key;
+
+       }
+
+
        public static int getUSKRevision(final String key) {
                String[] split;


Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-01-26 20:14:14 UTC 
(rev 11621)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-01-26 20:48:26 UTC 
(rev 11622)
@@ -564,9 +564,7 @@
                if(targetFile.exists()) {
                        Logger.info(this, "Inserting new version");

-                       String publicSSK = 
FreenetURIHelper.convertUSKtoSSK(publicKey);
-                       publicSSK = 
FreenetURIHelper.changeSSKRevision(publicSSK, rev, 1);
-                       publicKey = FreenetURIHelper.convertSSKtoUSK(publicSSK);
+                       String key = 
FreenetURIHelper.changeUSKRevision(publicKey, rev, 1);

                        rev++;

@@ -581,7 +579,7 @@
                        put.addObserver(this);
                        this.addObserver(o);

-                       setPublicKey(publicKey, rev);
+                       setPublicKey(key, rev);

                } else {
                        Logger.warning(this, "Index not generated !");


Reply via email to