Author: toad
Date: 2006-10-04 12:14:30 +0000 (Wed, 04 Oct 2006)
New Revision: 10598

Modified:
   trunk/freenet/src/freenet/client/Metadata.java
   trunk/freenet/src/freenet/client/async/SingleFileInserter.java
Log:
Fix the MetadataNotResolvedException when inserting large (multi-level; ~15M+) 
splitfiles with filenames.

Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java      2006-10-03 14:10:58 UTC 
(rev 10597)
+++ trunk/freenet/src/freenet/client/Metadata.java      2006-10-04 12:14:30 UTC 
(rev 10598)
@@ -722,7 +722,7 @@
        public void setSimpleRedirect() {
                documentType = SIMPLE_REDIRECT;
        }
-       
+
        /** Write the metadata as binary. 
         * @throws IOException If an I/O error occurred while writing the data. 
         * @throws MetadataUnresolvedException */

Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java      
2006-10-03 14:10:58 UTC (rev 10597)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java      
2006-10-04 12:14:30 UTC (rev 10598)
@@ -196,9 +196,6 @@
                        throw new 
InserterException(InserterException.INTERNAL_ERROR, "2GB+ should not encode to 
one block!", null);

                boolean noMetadata = ((block.clientMetadata == null) || 
block.clientMetadata.isTrivial()) && targetFilename == null;
-               if(metadata && !noMetadata) {
-                       throw new 
InserterException(InserterException.INTERNAL_ERROR, "MIME type set for a 
metadata insert!", null);
-               }
                if(noMetadata && !insertAsArchiveManifest) {
                        if(data.size() < blockSize) {
                                // Just insert it
@@ -439,30 +436,51 @@
                                onFailure(e, state);
                                return;
                        }
+                       
+                       byte[] metaBytes;
+                       try {
+                               metaBytes = meta.writeToByteArray();
+                       } catch (MetadataUnresolvedException e1) {
+                               Logger.error(this, "Impossible: "+e, e);
+                               InserterException ex = new 
InserterException(InserterException.INTERNAL_ERROR, 
"MetadataUnresolvedException in SingleFileInserter.SplitHandler: "+e1, null);
+                               ex.initCause(e1);
+                               fail(ex);
+                               return;
+                       }
+                       
+                       String metaPutterTargetFilename = targetFilename;
+                       
                        if(targetFilename != null) {
-                               HashMap hm = new HashMap();
-                               hm.put(targetFilename, meta);
-                               meta = 
Metadata.mkRedirectionManifestWithMetadata(hm);
+                               
+                               if(metaBytes.length <= Short.MAX_VALUE) {
+                                       HashMap hm = new HashMap();
+                                       hm.put(targetFilename, meta);
+                                       meta = 
Metadata.mkRedirectionManifestWithMetadata(hm);
+                                       metaPutterTargetFilename = null;
+                                       try {
+                                               metaBytes = 
meta.writeToByteArray();
+                                       } catch (MetadataUnresolvedException 
e1) {
+                                               Logger.error(this, "Impossible 
(2): "+e, e);
+                                               InserterException ex = new 
InserterException(InserterException.INTERNAL_ERROR, 
"MetadataUnresolvedException in SingleFileInserter.SplitHandler(2): "+e1, null);
+                                               ex.initCause(e1);
+                                               fail(ex);
+                                               return;
+                                       }
+                               }
                        }

                        Bucket metadataBucket;
                        try {
-                               metadataBucket = 
BucketTools.makeImmutableBucket(ctx.bf, meta.writeToByteArray());
+                               metadataBucket = 
BucketTools.makeImmutableBucket(ctx.bf, metaBytes);
                        } catch (IOException e1) {
                                InserterException ex = new 
InserterException(InserterException.BUCKET_ERROR, e1, null);
                                fail(ex);
                                return;
-                       } catch (MetadataUnresolvedException e1) {
-                               Logger.error(this, "Impossible: "+e, e);
-                               InserterException ex = new 
InserterException(InserterException.INTERNAL_ERROR, 
"MetadataUnresolvedException in SingleFileInserter.SplitHandler: "+e1, null);
-                               ex.initCause(e1);
-                               fail(ex);
-                               return;
                        }
                        InsertBlock newBlock = new InsertBlock(metadataBucket, 
null, block.desiredURI);
                        try {
                                synchronized(this) {
-                                       metadataPutter = new 
SingleFileInserter(parent, this, newBlock, true, ctx, false, getCHKOnly, false, 
token, false, true, null);
+                                       metadataPutter = new 
SingleFileInserter(parent, this, newBlock, true, ctx, false, getCHKOnly, false, 
token, false, true, metaPutterTargetFilename);
                                        if(!dataFetchable) return;
                                }
                                if(logMINOR) Logger.minor(this, "Putting 
metadata on "+metadataPutter+" from "+sfi+" 
("+((SplitFileInserter)sfi).getLength()+")");


Reply via email to